Click here to Skip to main content
15,893,508 members
Home / Discussions / C#
   

C#

 
GeneralRe: Linq to SQL With Enum On Null Field Pin
Kevin Marois2-Jul-22 9:40
professionalKevin Marois2-Jul-22 9:40 
GeneralRe: Linq to SQL With Enum On Null Field Pin
Dave Kreskowiak2-Jul-22 9:49
mveDave Kreskowiak2-Jul-22 9:49 
GeneralRe: Linq to SQL With Enum On Null Field Pin
Kevin Marois2-Jul-22 9:59
professionalKevin Marois2-Jul-22 9:59 
GeneralRe: Linq to SQL With Enum On Null Field Pin
OriginalGriff2-Jul-22 9:52
mveOriginalGriff2-Jul-22 9:52 
GeneralRe: Linq to SQL With Enum On Null Field Pin
Kevin Marois2-Jul-22 9:59
professionalKevin Marois2-Jul-22 9:59 
QuestionRe: Linq to SQL With Enum On Null Field Pin
Eddy Vluggen2-Jul-22 10:37
professionalEddy Vluggen2-Jul-22 10:37 
AnswerRe: Linq to SQL With Enum On Null Field Pin
Kevin Marois2-Jul-22 14:58
professionalKevin Marois2-Jul-22 14:58 
AnswerRe: Linq to SQL With Enum On Null Field Pin
Dave Kreskowiak2-Jul-22 4:59
mveDave Kreskowiak2-Jul-22 4:59 
GeneralRe: Linq to SQL With Enum On Null Field Pin
Kevin Marois2-Jul-22 9:43
professionalKevin Marois2-Jul-22 9:43 
AnswerRe: Linq to SQL With Enum On Null Field [MODIFIED] Pin
Richard Deeming4-Jul-22 21:40
mveRichard Deeming4-Jul-22 21:40 
QuestionStreaming data from one datalayer to another Pin
Evilfish200029-Jun-22 4:14
Evilfish200029-Jun-22 4:14 
AnswerRe: Streaming data from one datalayer to another Pin
Pete O'Hanlon29-Jun-22 20:46
mvePete O'Hanlon29-Jun-22 20:46 
PraiseRe: Streaming data from one datalayer to another Pin
Evilfish200029-Jun-22 21:40
Evilfish200029-Jun-22 21:40 
QuestionC# voice communication between 2 local pcs Pin
Getyourwings UK28-Jun-22 10:07
Getyourwings UK28-Jun-22 10:07 
QuestionIs there anything that Python or Java can do for windows GUI applications while C# can't ? Pin
Code4Ever24-Jun-22 2:33
Code4Ever24-Jun-22 2:33 
AnswerRe: Is there anything that Python or Java can do for windows GUI applications while C# can't ? Pin
Craig Robbins24-Jun-22 6:33
Craig Robbins24-Jun-22 6:33 
AnswerRe: Is there anything that Python or Java can do for windows GUI applications while C# can't ? Pin
Richard MacCutchan24-Jun-22 22:38
mveRichard MacCutchan24-Jun-22 22:38 
QuestionLinq TO SQL DistinctBy Question Pin
Kevin Marois23-Jun-22 18:16
professionalKevin Marois23-Jun-22 18:16 
AnswerRe: Linq TO SQL DistinctBy Question Pin
OriginalGriff23-Jun-22 19:49
mveOriginalGriff23-Jun-22 19:49 
GeneralRe: Linq TO SQL DistinctBy Question Pin
Richard Deeming23-Jun-22 22:36
mveRichard Deeming23-Jun-22 22:36 
AnswerRe: Linq TO SQL DistinctBy Question Pin
Richard Deeming23-Jun-22 22:43
mveRichard Deeming23-Jun-22 22:43 
It depends.

Are you using the DistinctBy method added in .NET 6, or a different implementation?

And does the ORM you're using translated DistinctBy to SQL, or does it evaluate it on the client?

If it evaluates it on the client, and you're using the .NET 6 method or something equivalent, then technically it will return the first item it encounters within each group.

However, this is an implementation detail, and you cannot rely on it. And since you don't order by the ID, you can't guarantee that the database will return the records in any ID-related order.

If you always want the lowest ID, then you need to be explicit:
C#
var jobSequenceSheets = dc.JobSequenceSheets
    .Where(jss => jss.JobId == jobId)
    .Where(jss => jss.RevisionNumber == maxRev)
    .GroupBy(jss => new { jss.Plan, jss.Elevation }, (_, items) => items.OrderBy(jss => jss.ID).First())
    .OrderBy(jss => jss.Plan).ThenBy(jss => jss.Elevation)
    .ToList();

NB: Depending on your ORM, you might need to stick an .AsEnumerable() between the second .Where(...) and the .GroupBy(...) to force client evaluation of the grouping.



"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer

QuestionDrawing with c# Pin
Member 1557095222-Jun-22 23:08
Member 1557095222-Jun-22 23:08 
AnswerRe: Drawing with c# Pin
Richard Deeming22-Jun-22 23:55
mveRichard Deeming22-Jun-22 23:55 
GeneralRe: Drawing with c# Pin
Member 1557095223-Jun-22 0:08
Member 1557095223-Jun-22 0:08 
GeneralRe: Drawing with c# Pin
Richard Deeming23-Jun-22 0:42
mveRichard Deeming23-Jun-22 0:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.