我有一个返回float的DB存储过程。存储过程执行输入计算并根据输入吐出“评级”。我能够更新模型并执行函数导入,但是当我尝试在Linq中使用新函数时,我得到以下错误。
中使用的函数元数据 DbFunctionExpression必须允许 组成。不可组合的功能 或包含命令文本的函数 表达式中不允许使用。
我不知道这意味着什么,Google搜索没有返回任何内容。
相关代码如下:
public static class EntityFunctions
{
[EdmFunction("RateMyNeighborhoodModel.Store","RMNIndex")]
public static decimal? RMNIndex
(
float Unemployment,
float AverageCommuteTime,
float FamiliesBelowPoverty,
float TotalCrime,
float PersonalCrime,
float Murder,
float Rape,
float Robbery,
float Assault,
float PropertyCrime,
float Burgulary,
float Larceny,
float VehicleTheft,
float SexOffenderCount
)
{
throw new NotSupportedException();
}
}
var neighborhoodViews = (from
nv in db.NeighborhoodViews
join
n in db.Neighborhoods.Include("ZipCodeStatistic") on nv.NeighborhoodID equals n.NeighborhoodID
where
EntityFunctions.RMNIndex((float)n.UnemploymentRate, (float)nv.AverageCommuteTime, (float)nv.familiesBelowPoverty, (float)nv.TotalCrime, (float)nv.PersonalCrime, (float)nv.Murder, (float)nv.Rape, (float)nv.Robbery, (float)nv.Assault, (float)nv.PropertyCrime, (float)nv.Burgulary, (float)nv.Larceny, (float)nv.VehicleTheft, (float)n.ZipCodeStatistic.SexOffenders) > 4
orderby
Guid.NewGuid()
select new
{
City = n.City,
GeographyData = nv.Geography,
ID = n.NeighborhoodID,
Latitude = Single.Parse(nv.Center.Replace("POINT (", "").Replace(")", "").Split(' ')[1]),
Longitude = Single.Parse(nv.Center.Replace("POINT (", "").Replace(")", "").Split(' ')[0]),
Name = n.Name,
State = n.State,
UpdateDate = n.UpdateDate,
RMNIndex = EntityFunctions.RMNIndex((float)n.UnemploymentRate, (float)nv.AverageCommuteTime, (float)nv.familiesBelowPoverty, (float)nv.TotalCrime, (float)nv.PersonalCrime, (float)nv.Murder, (float)nv.Rape, (float)nv.Robbery, (float)nv.Assault, (float)nv.PropertyCrime, (float)nv.Burgulary, (float)nv.Larceny, (float)nv.VehicleTheft, (float)n.ZipCodeStatistic.SexOffenders),
Zipcode = n.ZipCodeStatistic.ZipCode,
TotalCrime = (double)n.ZipCodeStatistic.TotalCrime,
PersonalCrime = (double)n.ZipCodeStatistic.PersonalCrime,
Murder = (double)n.ZipCodeStatistic.Murder,
Rape = (double)n.ZipCodeStatistic.Rape,
Robbery = (double)n.ZipCodeStatistic.Robbery,
Assault = (double)n.ZipCodeStatistic.Assault,
PropertyCrime = (double)n.ZipCodeStatistic.PropertyCrime,
Burgulary = (double)n.ZipCodeStatistic.Burgulary,
Larceny = (double)n.ZipCodeStatistic.Larceny,
VehicleTheft = (double)n.ZipCodeStatistic.VehicleTheft,
AverageCommuteTime = (double)n.ZipCodeStatistic.AverageCommuteTime,
UnemploymentRate = (double)n.ZipCodeStatistic.UnemploymentRate,
FamiliesBelowPoverty = (double)nv.familiesBelowPoverty,
SexOffenderCount = (int)n.ZipCodeStatistic.SexOffenders
}).Take(5);
答案 0 :(得分:1)
问题在于我使用的是存储过程和函数导入。当我将存储过程转换为标量函数时,我能够以我想要的方式使用它。