【发布时间】:2010-10-01 03:48:27
【问题描述】:
我有一个返回浮点数的数据库存储过程。存储过程对输入进行计算并根据输入输出“评级”。我能够更新模型并执行函数导入,但是当我尝试在 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);
【问题讨论】:
-
您的模型中是否将此函数的 IsComposable 属性设置为 true?
-
不,我没有。在网上的例子中,我不认为这是一个选项。我回家后会试试的。
标签: c# sql-server entity-framework