我想使用 SQL SERVER 的“In 子句”之类的东西。这是我的模型:
public partial class StationEvaluationBooks
{
public int StationEvaluationBookID { get; set; }
public Nullable<int> StationEvaluationID { get; set; }
public virtual StationEvaluation StationEvaluation { get; set; }
...
}
public partial class StationEvaluation
{
public StationEvaluation()
{
this.StationEvaluationBooks = new HashSet<StationEvaluationBooks>();
}
public int StationEvaluationID { get; set; }
public virtual ICollection<StationEvaluationBooks> StationEvaluationBooks { get; set; }
...
}
我使用以下代码通过 LINQ 实现“In 子句”,但出现错误:
StationsEntities db = new StationsEntities();
var stationevaluations = db.StationEvaluation;
//some conditions:
stationevaluations = stationevaluations.Where(/*condition*/);
..
var result = from c in db.StationEvaluationBooks
where stationevaluations.Contains(c.StationEvaluationID)
select c;
错误:“System.Data.Entity.DbSet”不包含“包含”的定义,并且最佳扩展方法重载“System.Linq.ParallelEnumerable.Contains(System.Linq.ParallelQuery, TSource)”有一些无效参数
编辑: 我想在 stationevaluations 变量中获取与所选评估相关的书籍。