Iterate through Linq to Entities results until condition is met









up vote
0
down vote

favorite
1












Here is the scenario, I have a query that returns events in a dat. Starting with shift start (SS) I need to find a shift end (SE) if I find it, move on to the next, if not, generate an error and record the row it happened on.



List<string> errorList = new List<string>();
List<int> errorListRow = new List<int>();
var itCompareDay = (from h in db.DailyGPSTables
where h.EmplID == EmpID
&& (h.EventDateTime >= startDate
&& h.EventDateTime <= endDate)
&& (h.EventType == "SS" || h.EventType == "JS" || h.EventType == "LS" || h.EventType == "LE" || h.EventType == "JE" || h.EventType == "SE")
orderby h.EventDateTime
select h).ToList();
int rowNumber = -1;
foreach (DailyGPSTable e in itCompareDay)
{
rowNumber = rowNumber + 1;
string EOOmessage="";
string eventText="";
int dayCountSs = itCompareDay.Count(k => k.EventType == "SS" && (k.EventDateTime.Value.ToShortDateString() == e.EventDateTime.Value.ToShortDateString()));
int dayCountSe = itCompareDay.Count(k => k.EventType == "SE" && (k.EventDateTime.Value.ToShortDateString() == e.EventDateTime.Value.ToShortDateString()));
int dayCountJS = itCompareDay.Count(k => k.EventType == "JS" && (k.EventDateTime.Value.ToShortDateString() == e.EventDateTime.Value.ToShortDateString()));
// Response.Write("<br> Count of event type is ss on " + e.EventDateTime.Value.ToShortDateString() + " is " + itCompareDay.Count(k => k.EventType == "SS" && k.EventDateTime.Value.ToShortDateString() == e.EventDateTime.Value.ToShortDateString()));
if (dayCountSs != dayCountSe)

eventText = "";
if (dayCountSs > dayCountSe)

eventText = "Shift End (SE)";

else

eventText = "Shift Start (SS)";

EOOmessage = " On " + e.EventDateTime.Value.ToShortDateString() + " there is a missing " + eventText;
errorList.Add(EOOmessage);
errorListRow.Add(rowNumber);



The above code returns an error for the entire day, I was heading down this path to find the line where a shift start had no ending tag and highlight that row. The day can have multiple shifts but have to have an ending tag.



if (dayCountSs != dayCountSe)
{
eventText = "";
if (dayCountSs > dayCountSe)

string dayEvents = e.EventType;
Response.Write("SS greater than SE >Event Type " + dayEvents +"<BR>");
for (int i = 0; i < dayCountSs; i++)

Response.Write("Should see a count here " + i);
if (dayEvents[i].ToString() != "SS")

i = i + 1;

else

errorListRow.Add(rowNumber);
eventText = "Shift End (SE)";



else

eventText = "Shift Start (SS)";

EOOmessage = " On " + e.EventDateTime.Value.ToShortDateString() + " there is a missing " + eventText;









share|improve this question



















  • 2




    Can you please provide a simple data example with which the error occurs? Your code readability is... lacking, which is hindering my understanding of the logical succession of operations you expect to have. An MCVE would be allround helpful here.
    – Flater
    Nov 9 at 15:01











  • @Hogan My question would be how do I iterate through the days events to find an unpaired SE tag. For example on 11/8/2018 I have 3 shifts and for that day I have 3 instances of the SS tag but only 2 SE tags which means the 3rd shift started but never ended. How do I find the 3rd SS tag to add an error condition to my list and record the row number?
    – Doug Farrell
    Nov 9 at 15:32










  • That is the problem you are trying to solve. We don't just write solutions for people here -- we help with questions. In trying to solve that problem did you run into something that did not work as expected. Is there a test case that fails, for example. We can answer a question -- as long as the question isn't -- how do I solve this problem write all the code for me. You have given us some code but no details on the problems you are having. If I have to spend 3 hours to understand the solution to answer your question, I'm not going to. If it takes me 10 mins then I'm happy to help.
    – Hogan
    Nov 9 at 17:21










  • You can find a lot of good resources in the help screens about how to ask a good question. In this case I would suggest giving us the input data and the expected output data and what your current code is doing. If you do this I expect someone will answer very quickly. (might even be me)
    – Hogan
    Nov 9 at 17:23















up vote
0
down vote

favorite
1












Here is the scenario, I have a query that returns events in a dat. Starting with shift start (SS) I need to find a shift end (SE) if I find it, move on to the next, if not, generate an error and record the row it happened on.



List<string> errorList = new List<string>();
List<int> errorListRow = new List<int>();
var itCompareDay = (from h in db.DailyGPSTables
where h.EmplID == EmpID
&& (h.EventDateTime >= startDate
&& h.EventDateTime <= endDate)
&& (h.EventType == "SS" || h.EventType == "JS" || h.EventType == "LS" || h.EventType == "LE" || h.EventType == "JE" || h.EventType == "SE")
orderby h.EventDateTime
select h).ToList();
int rowNumber = -1;
foreach (DailyGPSTable e in itCompareDay)
{
rowNumber = rowNumber + 1;
string EOOmessage="";
string eventText="";
int dayCountSs = itCompareDay.Count(k => k.EventType == "SS" && (k.EventDateTime.Value.ToShortDateString() == e.EventDateTime.Value.ToShortDateString()));
int dayCountSe = itCompareDay.Count(k => k.EventType == "SE" && (k.EventDateTime.Value.ToShortDateString() == e.EventDateTime.Value.ToShortDateString()));
int dayCountJS = itCompareDay.Count(k => k.EventType == "JS" && (k.EventDateTime.Value.ToShortDateString() == e.EventDateTime.Value.ToShortDateString()));
// Response.Write("<br> Count of event type is ss on " + e.EventDateTime.Value.ToShortDateString() + " is " + itCompareDay.Count(k => k.EventType == "SS" && k.EventDateTime.Value.ToShortDateString() == e.EventDateTime.Value.ToShortDateString()));
if (dayCountSs != dayCountSe)

eventText = "";
if (dayCountSs > dayCountSe)

eventText = "Shift End (SE)";

else

eventText = "Shift Start (SS)";

EOOmessage = " On " + e.EventDateTime.Value.ToShortDateString() + " there is a missing " + eventText;
errorList.Add(EOOmessage);
errorListRow.Add(rowNumber);



The above code returns an error for the entire day, I was heading down this path to find the line where a shift start had no ending tag and highlight that row. The day can have multiple shifts but have to have an ending tag.



if (dayCountSs != dayCountSe)
{
eventText = "";
if (dayCountSs > dayCountSe)

string dayEvents = e.EventType;
Response.Write("SS greater than SE >Event Type " + dayEvents +"<BR>");
for (int i = 0; i < dayCountSs; i++)

Response.Write("Should see a count here " + i);
if (dayEvents[i].ToString() != "SS")

i = i + 1;

else

errorListRow.Add(rowNumber);
eventText = "Shift End (SE)";



else

eventText = "Shift Start (SS)";

EOOmessage = " On " + e.EventDateTime.Value.ToShortDateString() + " there is a missing " + eventText;









share|improve this question



















  • 2




    Can you please provide a simple data example with which the error occurs? Your code readability is... lacking, which is hindering my understanding of the logical succession of operations you expect to have. An MCVE would be allround helpful here.
    – Flater
    Nov 9 at 15:01











  • @Hogan My question would be how do I iterate through the days events to find an unpaired SE tag. For example on 11/8/2018 I have 3 shifts and for that day I have 3 instances of the SS tag but only 2 SE tags which means the 3rd shift started but never ended. How do I find the 3rd SS tag to add an error condition to my list and record the row number?
    – Doug Farrell
    Nov 9 at 15:32










  • That is the problem you are trying to solve. We don't just write solutions for people here -- we help with questions. In trying to solve that problem did you run into something that did not work as expected. Is there a test case that fails, for example. We can answer a question -- as long as the question isn't -- how do I solve this problem write all the code for me. You have given us some code but no details on the problems you are having. If I have to spend 3 hours to understand the solution to answer your question, I'm not going to. If it takes me 10 mins then I'm happy to help.
    – Hogan
    Nov 9 at 17:21










  • You can find a lot of good resources in the help screens about how to ask a good question. In this case I would suggest giving us the input data and the expected output data and what your current code is doing. If you do this I expect someone will answer very quickly. (might even be me)
    – Hogan
    Nov 9 at 17:23













up vote
0
down vote

favorite
1









up vote
0
down vote

favorite
1






1





Here is the scenario, I have a query that returns events in a dat. Starting with shift start (SS) I need to find a shift end (SE) if I find it, move on to the next, if not, generate an error and record the row it happened on.



List<string> errorList = new List<string>();
List<int> errorListRow = new List<int>();
var itCompareDay = (from h in db.DailyGPSTables
where h.EmplID == EmpID
&& (h.EventDateTime >= startDate
&& h.EventDateTime <= endDate)
&& (h.EventType == "SS" || h.EventType == "JS" || h.EventType == "LS" || h.EventType == "LE" || h.EventType == "JE" || h.EventType == "SE")
orderby h.EventDateTime
select h).ToList();
int rowNumber = -1;
foreach (DailyGPSTable e in itCompareDay)
{
rowNumber = rowNumber + 1;
string EOOmessage="";
string eventText="";
int dayCountSs = itCompareDay.Count(k => k.EventType == "SS" && (k.EventDateTime.Value.ToShortDateString() == e.EventDateTime.Value.ToShortDateString()));
int dayCountSe = itCompareDay.Count(k => k.EventType == "SE" && (k.EventDateTime.Value.ToShortDateString() == e.EventDateTime.Value.ToShortDateString()));
int dayCountJS = itCompareDay.Count(k => k.EventType == "JS" && (k.EventDateTime.Value.ToShortDateString() == e.EventDateTime.Value.ToShortDateString()));
// Response.Write("<br> Count of event type is ss on " + e.EventDateTime.Value.ToShortDateString() + " is " + itCompareDay.Count(k => k.EventType == "SS" && k.EventDateTime.Value.ToShortDateString() == e.EventDateTime.Value.ToShortDateString()));
if (dayCountSs != dayCountSe)

eventText = "";
if (dayCountSs > dayCountSe)

eventText = "Shift End (SE)";

else

eventText = "Shift Start (SS)";

EOOmessage = " On " + e.EventDateTime.Value.ToShortDateString() + " there is a missing " + eventText;
errorList.Add(EOOmessage);
errorListRow.Add(rowNumber);



The above code returns an error for the entire day, I was heading down this path to find the line where a shift start had no ending tag and highlight that row. The day can have multiple shifts but have to have an ending tag.



if (dayCountSs != dayCountSe)
{
eventText = "";
if (dayCountSs > dayCountSe)

string dayEvents = e.EventType;
Response.Write("SS greater than SE >Event Type " + dayEvents +"<BR>");
for (int i = 0; i < dayCountSs; i++)

Response.Write("Should see a count here " + i);
if (dayEvents[i].ToString() != "SS")

i = i + 1;

else

errorListRow.Add(rowNumber);
eventText = "Shift End (SE)";



else

eventText = "Shift Start (SS)";

EOOmessage = " On " + e.EventDateTime.Value.ToShortDateString() + " there is a missing " + eventText;









share|improve this question















Here is the scenario, I have a query that returns events in a dat. Starting with shift start (SS) I need to find a shift end (SE) if I find it, move on to the next, if not, generate an error and record the row it happened on.



List<string> errorList = new List<string>();
List<int> errorListRow = new List<int>();
var itCompareDay = (from h in db.DailyGPSTables
where h.EmplID == EmpID
&& (h.EventDateTime >= startDate
&& h.EventDateTime <= endDate)
&& (h.EventType == "SS" || h.EventType == "JS" || h.EventType == "LS" || h.EventType == "LE" || h.EventType == "JE" || h.EventType == "SE")
orderby h.EventDateTime
select h).ToList();
int rowNumber = -1;
foreach (DailyGPSTable e in itCompareDay)
{
rowNumber = rowNumber + 1;
string EOOmessage="";
string eventText="";
int dayCountSs = itCompareDay.Count(k => k.EventType == "SS" && (k.EventDateTime.Value.ToShortDateString() == e.EventDateTime.Value.ToShortDateString()));
int dayCountSe = itCompareDay.Count(k => k.EventType == "SE" && (k.EventDateTime.Value.ToShortDateString() == e.EventDateTime.Value.ToShortDateString()));
int dayCountJS = itCompareDay.Count(k => k.EventType == "JS" && (k.EventDateTime.Value.ToShortDateString() == e.EventDateTime.Value.ToShortDateString()));
// Response.Write("<br> Count of event type is ss on " + e.EventDateTime.Value.ToShortDateString() + " is " + itCompareDay.Count(k => k.EventType == "SS" && k.EventDateTime.Value.ToShortDateString() == e.EventDateTime.Value.ToShortDateString()));
if (dayCountSs != dayCountSe)

eventText = "";
if (dayCountSs > dayCountSe)

eventText = "Shift End (SE)";

else

eventText = "Shift Start (SS)";

EOOmessage = " On " + e.EventDateTime.Value.ToShortDateString() + " there is a missing " + eventText;
errorList.Add(EOOmessage);
errorListRow.Add(rowNumber);



The above code returns an error for the entire day, I was heading down this path to find the line where a shift start had no ending tag and highlight that row. The day can have multiple shifts but have to have an ending tag.



if (dayCountSs != dayCountSe)
{
eventText = "";
if (dayCountSs > dayCountSe)

string dayEvents = e.EventType;
Response.Write("SS greater than SE >Event Type " + dayEvents +"<BR>");
for (int i = 0; i < dayCountSs; i++)

Response.Write("Should see a count here " + i);
if (dayEvents[i].ToString() != "SS")

i = i + 1;

else

errorListRow.Add(rowNumber);
eventText = "Shift End (SE)";



else

eventText = "Shift Start (SS)";

EOOmessage = " On " + e.EventDateTime.Value.ToShortDateString() + " there is a missing " + eventText;






c# asp.net linq






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 9 at 14:52









Hogan

54k863100




54k863100










asked Nov 9 at 14:37









Doug Farrell

175




175







  • 2




    Can you please provide a simple data example with which the error occurs? Your code readability is... lacking, which is hindering my understanding of the logical succession of operations you expect to have. An MCVE would be allround helpful here.
    – Flater
    Nov 9 at 15:01











  • @Hogan My question would be how do I iterate through the days events to find an unpaired SE tag. For example on 11/8/2018 I have 3 shifts and for that day I have 3 instances of the SS tag but only 2 SE tags which means the 3rd shift started but never ended. How do I find the 3rd SS tag to add an error condition to my list and record the row number?
    – Doug Farrell
    Nov 9 at 15:32










  • That is the problem you are trying to solve. We don't just write solutions for people here -- we help with questions. In trying to solve that problem did you run into something that did not work as expected. Is there a test case that fails, for example. We can answer a question -- as long as the question isn't -- how do I solve this problem write all the code for me. You have given us some code but no details on the problems you are having. If I have to spend 3 hours to understand the solution to answer your question, I'm not going to. If it takes me 10 mins then I'm happy to help.
    – Hogan
    Nov 9 at 17:21










  • You can find a lot of good resources in the help screens about how to ask a good question. In this case I would suggest giving us the input data and the expected output data and what your current code is doing. If you do this I expect someone will answer very quickly. (might even be me)
    – Hogan
    Nov 9 at 17:23













  • 2




    Can you please provide a simple data example with which the error occurs? Your code readability is... lacking, which is hindering my understanding of the logical succession of operations you expect to have. An MCVE would be allround helpful here.
    – Flater
    Nov 9 at 15:01











  • @Hogan My question would be how do I iterate through the days events to find an unpaired SE tag. For example on 11/8/2018 I have 3 shifts and for that day I have 3 instances of the SS tag but only 2 SE tags which means the 3rd shift started but never ended. How do I find the 3rd SS tag to add an error condition to my list and record the row number?
    – Doug Farrell
    Nov 9 at 15:32










  • That is the problem you are trying to solve. We don't just write solutions for people here -- we help with questions. In trying to solve that problem did you run into something that did not work as expected. Is there a test case that fails, for example. We can answer a question -- as long as the question isn't -- how do I solve this problem write all the code for me. You have given us some code but no details on the problems you are having. If I have to spend 3 hours to understand the solution to answer your question, I'm not going to. If it takes me 10 mins then I'm happy to help.
    – Hogan
    Nov 9 at 17:21










  • You can find a lot of good resources in the help screens about how to ask a good question. In this case I would suggest giving us the input data and the expected output data and what your current code is doing. If you do this I expect someone will answer very quickly. (might even be me)
    – Hogan
    Nov 9 at 17:23








2




2




Can you please provide a simple data example with which the error occurs? Your code readability is... lacking, which is hindering my understanding of the logical succession of operations you expect to have. An MCVE would be allround helpful here.
– Flater
Nov 9 at 15:01





Can you please provide a simple data example with which the error occurs? Your code readability is... lacking, which is hindering my understanding of the logical succession of operations you expect to have. An MCVE would be allround helpful here.
– Flater
Nov 9 at 15:01













@Hogan My question would be how do I iterate through the days events to find an unpaired SE tag. For example on 11/8/2018 I have 3 shifts and for that day I have 3 instances of the SS tag but only 2 SE tags which means the 3rd shift started but never ended. How do I find the 3rd SS tag to add an error condition to my list and record the row number?
– Doug Farrell
Nov 9 at 15:32




@Hogan My question would be how do I iterate through the days events to find an unpaired SE tag. For example on 11/8/2018 I have 3 shifts and for that day I have 3 instances of the SS tag but only 2 SE tags which means the 3rd shift started but never ended. How do I find the 3rd SS tag to add an error condition to my list and record the row number?
– Doug Farrell
Nov 9 at 15:32












That is the problem you are trying to solve. We don't just write solutions for people here -- we help with questions. In trying to solve that problem did you run into something that did not work as expected. Is there a test case that fails, for example. We can answer a question -- as long as the question isn't -- how do I solve this problem write all the code for me. You have given us some code but no details on the problems you are having. If I have to spend 3 hours to understand the solution to answer your question, I'm not going to. If it takes me 10 mins then I'm happy to help.
– Hogan
Nov 9 at 17:21




That is the problem you are trying to solve. We don't just write solutions for people here -- we help with questions. In trying to solve that problem did you run into something that did not work as expected. Is there a test case that fails, for example. We can answer a question -- as long as the question isn't -- how do I solve this problem write all the code for me. You have given us some code but no details on the problems you are having. If I have to spend 3 hours to understand the solution to answer your question, I'm not going to. If it takes me 10 mins then I'm happy to help.
– Hogan
Nov 9 at 17:21












You can find a lot of good resources in the help screens about how to ask a good question. In this case I would suggest giving us the input data and the expected output data and what your current code is doing. If you do this I expect someone will answer very quickly. (might even be me)
– Hogan
Nov 9 at 17:23





You can find a lot of good resources in the help screens about how to ask a good question. In this case I would suggest giving us the input data and the expected output data and what your current code is doing. If you do this I expect someone will answer very quickly. (might even be me)
– Hogan
Nov 9 at 17:23













1 Answer
1






active

oldest

votes

















up vote
0
down vote













Using the same extensions methods from your other question, the same code should work, just for SS/SE instead of JS/JE:



var shiftErrEvents = itCompareDay
.Select((ev, rowNum) => new ev.EventType, ev.EventDateTime, rowNum )
.Where(cd => cd.EventType == "SS" || cd.EventType == "SE")
.GroupByWhile((pd, cd) => pd.EventType == "SS" && cd.EventType == "SE" && pd.EventDateTime.Date == cd.EventDateTime.Date)
.Where(cdg => cdg.Count() != 2)
.SelectMany(cdg => cdg.Select(cd => new cd.rowNum, ErrMsg = cd.EventType == "SE" ? "SE without preceding SS" : "SS without following SE" ));


Note: In both cases, a job or shift that crosses the midnight boundary (hence, is on different days) will be handled as two mismatched events.






share|improve this answer




















    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













     

    draft saved


    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53227797%2fiterate-through-linq-to-entities-results-until-condition-is-met%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote













    Using the same extensions methods from your other question, the same code should work, just for SS/SE instead of JS/JE:



    var shiftErrEvents = itCompareDay
    .Select((ev, rowNum) => new ev.EventType, ev.EventDateTime, rowNum )
    .Where(cd => cd.EventType == "SS" || cd.EventType == "SE")
    .GroupByWhile((pd, cd) => pd.EventType == "SS" && cd.EventType == "SE" && pd.EventDateTime.Date == cd.EventDateTime.Date)
    .Where(cdg => cdg.Count() != 2)
    .SelectMany(cdg => cdg.Select(cd => new cd.rowNum, ErrMsg = cd.EventType == "SE" ? "SE without preceding SS" : "SS without following SE" ));


    Note: In both cases, a job or shift that crosses the midnight boundary (hence, is on different days) will be handled as two mismatched events.






    share|improve this answer
























      up vote
      0
      down vote













      Using the same extensions methods from your other question, the same code should work, just for SS/SE instead of JS/JE:



      var shiftErrEvents = itCompareDay
      .Select((ev, rowNum) => new ev.EventType, ev.EventDateTime, rowNum )
      .Where(cd => cd.EventType == "SS" || cd.EventType == "SE")
      .GroupByWhile((pd, cd) => pd.EventType == "SS" && cd.EventType == "SE" && pd.EventDateTime.Date == cd.EventDateTime.Date)
      .Where(cdg => cdg.Count() != 2)
      .SelectMany(cdg => cdg.Select(cd => new cd.rowNum, ErrMsg = cd.EventType == "SE" ? "SE without preceding SS" : "SS without following SE" ));


      Note: In both cases, a job or shift that crosses the midnight boundary (hence, is on different days) will be handled as two mismatched events.






      share|improve this answer






















        up vote
        0
        down vote










        up vote
        0
        down vote









        Using the same extensions methods from your other question, the same code should work, just for SS/SE instead of JS/JE:



        var shiftErrEvents = itCompareDay
        .Select((ev, rowNum) => new ev.EventType, ev.EventDateTime, rowNum )
        .Where(cd => cd.EventType == "SS" || cd.EventType == "SE")
        .GroupByWhile((pd, cd) => pd.EventType == "SS" && cd.EventType == "SE" && pd.EventDateTime.Date == cd.EventDateTime.Date)
        .Where(cdg => cdg.Count() != 2)
        .SelectMany(cdg => cdg.Select(cd => new cd.rowNum, ErrMsg = cd.EventType == "SE" ? "SE without preceding SS" : "SS without following SE" ));


        Note: In both cases, a job or shift that crosses the midnight boundary (hence, is on different days) will be handled as two mismatched events.






        share|improve this answer












        Using the same extensions methods from your other question, the same code should work, just for SS/SE instead of JS/JE:



        var shiftErrEvents = itCompareDay
        .Select((ev, rowNum) => new ev.EventType, ev.EventDateTime, rowNum )
        .Where(cd => cd.EventType == "SS" || cd.EventType == "SE")
        .GroupByWhile((pd, cd) => pd.EventType == "SS" && cd.EventType == "SE" && pd.EventDateTime.Date == cd.EventDateTime.Date)
        .Where(cdg => cdg.Count() != 2)
        .SelectMany(cdg => cdg.Select(cd => new cd.rowNum, ErrMsg = cd.EventType == "SE" ? "SE without preceding SS" : "SS without following SE" ));


        Note: In both cases, a job or shift that crosses the midnight boundary (hence, is on different days) will be handled as two mismatched events.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 9 at 19:43









        NetMage

        12.6k11734




        12.6k11734



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53227797%2fiterate-through-linq-to-entities-results-until-condition-is-met%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Use pre created SQLite database for Android project in kotlin

            Darth Vader #20

            Ondo