我有一个在SQL数据库中的标量函数,我想使用Linq to Entity context调用它。
虽然我知道,你可以使用以下语法调用表函数。
[DbFunction("Context", "TableFunc")]
public virtual IQueryable<ModelEntity> TableFunc(int
Id)
{
var IdParam = new ObjectParameter("Id", typeof(int))
{
Value = Id
};
return (this as IObjectContextAdapter).ObjectContext
.CreateQuery<ModelEntity>(
"Context.TableFunc(@Id)",IdParam);
}
然而,如果我在这个地方使用标量函数。
我会得到一个错误提示:“未指定名称参数”。
我的标量函数没有任何参数。
更新:
标量函数调用。
[DbFunction("Context","GetValue")]
public virtual IQueryable<short> GetValue()
{
return (this as
IObjectContextAdapter).ObjectContext.CreateQuery<short>
("Context.GetValue()");
}
.CreateQuery<ModelEntity>("SELECT ScalarFunc()");
做了什么?(在返回值前面添加 SELECT 函数名称) - Caius Jardnew ObjectParameter("@Id", typeof(int))
。 - ASpirin