BLToolkit - 由于对象的当前状态,操作无效

时间:2013-08-30 08:51:26

标签: asp.net-mvc linq bltoolkit

我们在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到十进制转换。

1 个答案:

答案 0 :(得分:0)

我认为这不是BltToolkit的例外。请通过以下链接查看答案:[1]

我的来源:

[1] 'Operation is not valid due to the current state of the object' error during postback