将float转换为double时的实体框架错误

时间:2012-09-17 16:05:14

标签: sql-server entity-framework-4

我有一个存储过程,它以下表的形式返回数据

ID int null,
RestaurentName varchar(250),
Address nvarchar(150),
Area nvarchar(150),
City nvarchar(50),
Postcode nvarchar(50),
DeliveryPrice decimal(4,2),
DeliveryTime nvarchar(50),
Latitude nvarchar(50),
Longitude nvarchar(50),
LogoLocation nvarchar(50),
Rating float,// returns AVG of rating
Discount money

我在EF中输入了一个函数。 现在,当我运行该网站时,我有以下错误

  

'SearchRestaurantByKey_Result'上的'Rating'属性不可能   设置为'Double'值。您必须将此属性设置为非null   “十进制”类型的值。

有没有人知道如何解决这个问题?

修改 这是我遇到错误的地方:

var query = (from p in dc.GetRestaurantByAreaAndCategory(area,type)
                         select new RestaurantViewModel()
                         {
                             Name = p.RestaurentName,
                             Address = p.Address,
                             City = p.City,
                             Postcode = p.Postcode,
                             ID = Convert.ToInt32(p.ID),
                             LogoPath = p.LogoLocation,
                             DeliveryPrice = Convert.ToDecimal(p.DeliveryPrice),
                             DeliveryTime = p.DeliveryTime,
                             discount = p.Discount,
                             Rating=Convert.ToDouble(p.Rating) //here is the error.

                         }).ToList();

在RestaurantViewModel()中,rating属性为Double。

0 个答案:

没有答案