score:3
Accepted answer
Try giving names to the properties in your anonymous objects:
var ccrCodes = (from c in db.CCRCodes
join i in items on
new { FamCode = c.baan_cat_fam_code, CatCode = c.baan_cat_code } equals
new { FamCode = i.baan_cat_family_code, CatCode = i.baan_cat_code }
where i => i.contact_dt.Value.Year == date.Year && i.contact_dt.Value.Month == date.Month
select c).Distinct().OrderBy(c => c.code_desc);
EDIT: Alright, I have to confess, I am no expert on query syntax, but you want to filter the 'items' list before doing the join, like the following fluent version of your query:
db.CCRCodes
.Join(
items.Where(i => i.contact_dt.Value.Year == date.Year && i.contact_dt.Value.Month == date.Month),
x => new { FamCode = x.baan_cat_fam_code, CatCode = x.baan_cat_code },
x => new { FamCode = x.baan_cat_family_code, CatCode = x.baan_cat_code },
(o,i) => o
).Distinct().OrderBy(c => c.code_desc)
ANOTHER EDIT: Per Ahmad's suggestion:
var ccrCodes = (from c in db.CCRCodes
join i in items.Where(x => x.contact_dt.Value.Year == date.Year && x.contact_dt.Value.Month == date.Month) on
new { FamCode = c.baan_cat_fam_code, CatCode = c.baan_cat_code } equals
new { FamCode = i.baan_cat_family_code, CatCode = i.baan_cat_code }
select c).Distinct().OrderBy(c => c.code_desc);
YET ANOTHER EDIT: Per another Ahmad suggestion:
var ccrCodes = (from c in db.CCRCodes
from i in items
where i.contact_dt.Value.Year == date.Year && i.contact_dt.Value.Month == date.Month
&& c.baan_cat_fam_code == i.baan_cat_family_code && c.baan_cat_code == i.baan_cat_code
select c).Distinct().OrderBy(c => c.code_desc);
Source: stackoverflow.com
Related Query
- Left outer join using LINQ -- understanding the code
- LINQ Source Code Available
- How can I code an outer join using LINQ and EF6?
- creating Linq to sqlite dbml from DbLinq source code
- LINQ Join Errors
- source code for LINQ 101 samples
- Linq code have errors when i use Distinct()
- How to join one row to every row in source table using LINQ
- Errors trying to Linq join and pass back a ViewModel C# MVC
- c# Linq or code to extract groups from a single list of source data
- LINQ - outer join to parent class in EF code first
- Convert sql code to linq (Inner join Query)
- linq join code doesn't work
- Why this multi linq join code does not work?
- LEFT OUTER JOIN in LINQ
- How do you perform a left outer join using linq extension methods
- Convert string[] to int[] in one line of code using LINQ
- How to do joins in LINQ on multiple fields in single join
- LINQ - Full Outer Join
- Code equivalent to the 'let' keyword in chained LINQ extension method calls
- LINQ to SQL - Left Outer Join with multiple join conditions
- LINQ to SQL Left Outer Join
- How do you perform a CROSS JOIN with LINQ to SQL?
- LINQ Join with Multiple Conditions in On Clause
- Linq code to select one item
- How to perform Join between multiple tables in LINQ lambda
- Why is LINQ JOIN so much faster than linking with WHERE?
- Convert SQL to Linq left join with null
- LEFT JOIN in LINQ to entities?
- LINQ to SQL multiple tables left outer join
More Query from same tag
- Dynamic linq query not working
- Linq query that return N results from two grouped columns
- Filter LINQ To Entities (EF Core) query by List of HashSet of String and Enum
- Running an existing LINQ query against a dynamic object (DataTable like)
- How to debug an empty LINQ result query?
- How to check in a linq query for null?
- C# - Linq : Unable to create a constant value of type Only primitive types or enumeration types are supported in this context.
- Upgrading to EntityFramework 6.1.3 and now receiving context exceptions
- Left OuterJoin in Entity/Linq
- Linq Select with inner method error - LINQ to Entities does not recognize the method
- best way to convert collection to string
- How to write Parsed and extracted data in XML before SqlServer Database insertion
- Using LINQ to group together a list of nodes and a list of their attributes
- Could/should these these three queries be combined into one?
- Dynamic Where in Linq query to get all results or limit by one
- LINQ to SQL with group by clause with aggregate function
- Query Parent's record where condition on a Grandchild
- How can I compare 2 XML Documents?
- Why am I getting a null exception when trying to assign a value to a nested object in C# asp.net 5?
- Explanation of this LINQ expression
- Linq Contains value in list
- Entity Framework 4 generated queries are joining full tables
- Check if a list of integers increments by one
- Convert the class as data table using extension method and lambda expression
- Find a dupe in a List with Linq
- How to use LINQ with a 2 dimensional array
- group by base on 2 element
- How can I use ':' character in a name of XDocument element?
- How to convert SQL with LEFT JOIN to EF CORE 3 LINQ
- .NET Linq. Confusion about SelectMany