I have a DB stored procedure that returns a float. The Stored proc does calculations of inputs and spits out a "Rating" based in the inputs. I was able to update the Model and perform a function import, but when I try and use the new function in Linq i get the following error.
Function metadata used in DbFunctionExpression must allow composition. Non-composable functions or functions that include command text are not allowed in expressions.
I have no idea what that means, and a Google search returned nothing.
Relevant code follows:
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);