3

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);
2
  • 1
    Do you have the IsComposable attribute set to true for this function in your model? Commented Oct 1, 2010 at 15:54
  • No I don't. In the examples online I didn't see that as an option. I will try that when I get home. Commented Oct 1, 2010 at 16:25

1 Answer 1

1

The problem was that I was using a Stored Procedure and a function import. When i converted the stored procedure to a scalar function I was able to use it the way I had intended.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.