Skip to main content

Posts

Showing posts with the label LINQ

LINQ Join with Multiple Conditions in On Clause in C#

Code First Approach: Here you go with: from b in _dbContext . Burden join bl in _dbContext . BurdenLookups on new { Organization_Type = b . Organization_Type_ID , Cost_Type = b . Cost_Type_ID } equals new { Organization_Type = bl . Organization_Type_ID , Cost_Type = bl . Cost_Type_ID } Second Approach You just need to name the anonymous property the same on both sides on new { t1 . ProjectID , SecondProperty = true } equals new { t2 . ProjectID , SecondProperty = t2 . Completed } into j1 Based on the comments of @svick, here is another implementation that might make more sense: from t1 in Projects from t2 in Tasks . Where ( x => t1 . ProjectID == x . ProjectID && x . Completed == true ) . DefaultIfEmpty () select new { t1 . ProjectName , t2 . TaskName } Link LINQ Join with Multiple Conditions in On Clause

Possible errors in Entity Framework Core and their solutions

 1) This error is exactly same as the self referencing error in the ASP.NET when using swagger UI. Solution: If you are using .NET Core. Using this in startup.cs file services .AddMvc() .AddJsonOptions(x => x.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore); 2)