2010-10-01 44 views
2

我有一個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); 
+1

您的模型中的此函數是否將IsComposable屬性設置爲true? – Devart 2010-10-01 15:54:48

+0

不,我不知道。在網上的例子中,我沒有看到這是一個選項。當我回家時我會嘗試。 – 2010-10-01 16:25:19

回答

1

的問題是,我是使用存儲過程和函數導入。當我將存儲過程轉換爲標量函數時,我能夠按照我的意圖使用它。

+0

好。我喜歡它 – AEMLoviji 2010-10-02 05:24:43