I struggled constructing and finding easily the correct info for defining the LINQ expressing for the criterion on the many-to-many, hence the Q&A.
Please modify/improve/correct/...
Basic situation:
- .Net Entity Framework code first
- We work with UnitOfWork repo's, but that's not really important here
- We define a
IQueryable<MyCustomMadeEntity>
query - User submits his search criteria through a form, each criterion matching either directly a property of MyCustomMadeEntity, or a property of an another entity that has a many-to-many-relationship with MyCustomMadeEntity, e.g.:
public class MyCustomMadeEntity : BaseEntity
{
public string ArticleCode { get; set; }
public string Comment { get; set; }
public Guid? ColorId { get; set; }
public ArticleColor Color { get; set; }
public ICollection<ArticleStatus> ArticleStatuses { get; set; }
}
with
public class MyCustomMadeEntity : BaseEntity
{
// properties
Public LocationType LocationType { get; set; }
}
(In the case LocationType is a custom made enum