我们在ASP.NET MVC 4应用程序中使用BLToolkit库。在尝试执行以下LINQ语句时,我得到一个"由于对象的当前状态,操作无效":
public List<Domain.Entities.Department_Facility> GetByDepartmentId(uint departmentId, uint fiscalYearId)
{
using (var db = new AabViftenDb())
{
BLToolkit.Common.Configuration.Linq.AllowMultipleQuery = true;
var result = (from df in db.department_facilities
where df.Department_ID == departmentId
&& df.departmentfacilityfiscalyearibfk1.Count() > 0
orderby df.ID descending
select new Department_Facility
{
ID = df.ID,
Description = df.Description,
EstablishedYear = df.EstablishedYear,
Facility = new Facility { ID = df.fkDepartmentFacilityfacility1.ID,
Name = df.fkDepartmentFacilityfacility1.Name,
Key= df.fkDepartmentFacilityfacility1.Key
},
LifeCycleYears = df.LifeCycleYears,
FacilityFiscalYear = (from ff in df.departmentfacilityfiscalyearibfk1
where ff.HousingAssociationFiscalYear_ID == fiscalYearId
select new Facility_FiscalYear
{
FiscalYear = new FiscalYears { ID = ff.departmentfacilityfiscalyearibfk2.ID,
FiscalYear = ff.departmentfacilityfiscalyearibfk2.FiscalYear },
ItemCount = ff.ItemCount
}).FirstOrDefault()
}).ToList();
return result;
}
}
型号:
public class Department_Facility
{
public uint ID { get; set; }
public Department Department { get;set; }
public Facility Facility { get; set; }
public ushort EstablishedYear { get; set; }
public decimal LifeCycleYears { get; set; }
public string Description { get; set; }
public Facility_FiscalYear FacilityFiscalYear { get; set; }
}
public class Facility_FiscalYear
{
public FiscalYears FiscalYear { get; set; }
public decimal ItemCount { get; set; }
}
df。LifeCycleYears和ff.ItemCount具有ushort类型,因此在上面的LINQ语句中有一个隐含的ushort到十进制的转换。
我认为这不是BltToolkit的例外。请检查此链接的答案:[1]
我的来源:
[1] ';由于对象的当前状态,操作无效';回发时出错