gpt4 book ai didi

c# - Entity Framework 和函数导入的错误消息

转载 作者:太空宇宙 更新时间:2023-11-03 14:26:26 25 4
gpt4 key购买 nike

我有一个返回 float 的数据库存储过程。 Stored proc 计算输入并根据输入吐出一个“评级”。我能够更新模型并执行函数导入,但是当我尝试在 Linq 中使用新函数时,出现以下错误。

Function metadata used in DbFunctionExpression must allow composition. Non-composable functions or functions that include command text are not allowed in expressions.

我不知道那是什么意思,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);

最佳答案

问题是我使用的是存储过程和函数导入。当我将存储过程转换为标量函数时,我能够按照预期的方式使用它。

关于c# - Entity Framework 和函数导入的错误消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3836421/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com