1、NuGet包管理中,安装EntityFramework.Functions
2、在EF的上下文Context中写Function的信息
[Function(FunctionType.NonComposableScalarValuedFunction, nameof(GetFossilListCount), Schema = "dbo")]
[return: Parameter(DbType = "int")]
public int GetFossilListCount([Parameter(DbType = "int")]int sectionID)
{
ObjectParameter parameter = new ObjectParameter(nameof(sectionID), sectionID);
return this.ObjectContext().ExecuteFunction<int>(nameof(this.GetFossilListCount), parameter).SingleOrDefault();
}
3、在EF的上下文Context中的OnModelCreating方法中,加入
// Add functions on AdventureWorks to entity model.
modelBuilder.Conventions.Add(new FunctionConvention<ProductContext>());
4、最终调用
vo.Lithostratigraphy = entities.GetFossilListCount(item.SectionID)>0?true:false;