【发布时间】:2019-06-12 17:08:23
【问题描述】:
这可能是一个简单/愚蠢的问题,但他们是否可以根据您收到的数据将内部或外部联接添加到 SQL 查询(使用实体框架)?
示例
public bool method(int? typeId, int? categoryId){
var query = from o in _dbContext.SomeObjects;
//JOIN type
if(typeId != null){
//Add inner join with table types to query
//Something like:
//query += join type in _dbContext.Types on o.TypeId equals type.ID
}else{
//Add outer join with table types to query
//query += join type in _dbContext.Types on o.TypeId equals type.ID into types
// from type in types.DefaultIfEmpty()
}
//Do same for category
...
//Filters
if(typeId != null){
query += where type.ID == typeId
}
if(categoryId != null){
query += where category.ID == categoryId
}
}
【问题讨论】:
-
有点类似question
-
有点,但我想知道如何用asp ef语法编写它
标签: c# sql join asp.net-core entity-framework-core