仅支持ASP.Net MVC初始化程序,实体成员和实体导航属性

时间:2015-12-14 04:36:27

标签: c# asp.net asp.net-mvc entity-framework linq

我有一个定义为

的模型类
public partial class RoadSegCond
{

    public int ThanaID { get; set; }
    public short RoadID { get; set; }
    public int FromChain { get; set; }
    public virtual SurfaceType SurfaceType { get; set; } 
}

public partial class SurfaceType
{
    public int Id { get; set; }
    public string Name { get; set; }
    public string Code { get; set; }
}

public class SegmentWiseConditionViewModel
{
    public int ThanaID { get; set; }
    public short RoadID { get; set; }
    public int FromChain { get; set; }      
    public string surfaceType { get; set; }
}

在我的控制器中,我想将信息发送到View模型,但它显示了 错误 LINQ to Entities中不支持指定的类型成员'SurfaceType'。仅支持初始值设定项,实体成员和实体导航属性。

我的控制器是

 public ActionResult Read([DataSourceRequest]DataSourceRequest request)
 {
        var model = from r in new RSDMSEntities().RoadSegConds
                    select new SegmentWiseConditionViewModel
                    {
                        RoadID = r.RoadID,
                        ThanaID = r.ThanaID,
                        FromChain = r.FromChain,
                        SurfaceType = r.SurfaceType.Name,
                    };


        DataSourceResult result = model.ToDataSourceResult(request);

        return Json(result);

 }

viewmodel

 public class SegmentWiseConditionViewModel
{
    public int ThanaID { get; set; }
    public short RoadID { get; set; }
    public int FromChain { get; set; }
    public string surfaceType { get; set; }

}

0 个答案:

没有答案