类型' System.NotSupportedException'的例外情况发生在EntityFramework.SqlServer.dll中

时间:2014-10-20 06:19:21

标签: c# .net sql-server entity-framework

我正在尝试使用连接来获取数据,但是当我得到ParentHireGroupName时它会显示错误。当我对这行代码做评论时它工作正常!

功能

public IList<RptFleetHireGroupDetail> GetFleetReport()
        {
            var fleetHireGroupDetailQuery = from vehicle in DbSet                
                join hgd in db.HireGroupDetails on
                    new {ModelID = vehicle.VehicleModelId, MakeID = vehicle.VehicleMakeId, CategoryId = vehicle.VehicleCategoryId, Year= vehicle.ModelYear }
                    equals new { ModelID = hgd.VehicleMakeId, MakeID = hgd.VehicleMakeId, CategoryId = hgd.VehicleCategoryId, Year = hgd.ModelYear }
                select new RptFleetHireGroupDetail
                {
                    HireGroupName = hgd.HireGroup.HireGroupName,
                    PlateNumber = vehicle.PlateNumber,
                    ParentHireGroupName = hgd.HireGroup.ParentHireGroup!=null? "kuch to hai":string.Empty,

                };
            return fleetHireGroupDetailQuery.OrderBy(fhgd => fhgd.FleetPoolName).ToList();
        }

RptFleetHireGroupDetail

public class RptFleetHireGroupDetail
    {
        #region Public
        public string HireGroupName { get; set; }
        public string ParentHireGroupName { get; set; }
        public string PlateNumber { get; set; }
        #endregion
}

其他错误信息: Cannot compare elements of type 'HireGroup'. Only primitive types, enumeration types and entity types are supported.

0 个答案:

没有答案