English 中文(简体)
Linq tokou and MVC 2 《地图集》成员。 我的财富没有规划。 -COM PlusExceptionCode=532462766
原标题:Linq to SQL and MVC 2 "Class member MyClass.MyProperty is unmapped. _COMPlusExceptionCode = -532462766

事先感谢聆听我的问题。

我有一个Linq到Sql级,在我使用“观点”的Grid岛上正在展示具体特性。

首先,我通过部分班子对我的班级施加影响:

    public string Owner { get; private set; }
    public Int32 Documents { get; private set; }

    partial void OnLoaded()
    {
        Owner = "PersonCompanyRoleMedicalExam";
        Documents = sfdb.StoredFiles.Count(s => s.Owner == this.Owner && s.OwnerId == this.Id);
    }

Next ill paste my ViewModel used for the Grid:

public class MedicalExamViewModel
{
    public Int32 Id { get; set; }
    public Int32 PersonCompanyRoleId { get; set; }
    public Int32? PeriodInDays { get; set; }
    public DateTime? ExamCompleted { get; set; }
    public bool? MedicallyFit { get; set; }
    public Int32 Documents { get; set; }
}

之后,我用我的电网发出亚克斯呼吁的方法,将其填满:

    [GridAction]
    public ActionResult _MedicalExamGridAjaxBinding(Int32 Id)
    {
        PersonCompanyRole personCompanyRole = db.PersonCompanyRoles.Single(p => p.PersonId == Id);

        var model = from o in db.PersonCompanyRoleMedicalExams
                    where o.PersonCompanyRoleId == personCompanyRole.Id
                    select new MedicalExamViewModel
                    {
                        Id = o.Id,
                        PersonCompanyRoleId = o.PersonCompanyRoleId,
                        PeriodInDays = o.PeriodInDays,
                        ExamCompleted = o.ExamCompleted,
                        MedicallyFit = o.MedicallyFit,
                        Documents = o.Documents
                    };

        return View(new GridModel
        {
            Data = model
        });
    }

在我刚刚结束的“老模型”一栏“从 d到 d”一栏,看物体一打基础{System.SystemException} ={“Class members ComppanyRoleSHEAppointment.Documents is unmapped}

更深入地将物体分解为系统例外。 系统外观,在InnerException中,它指出:_COM PlusExceptionCode = -532462766。

不可否认的是,在我的项目中,我使用完全相同的技术,在没有任何问题的情况下,把其他物体/模型列入清单,但有一个不同之处,即两者之间有一个关联表。 与此类似:个人——和;个人CompanyRole > 个人CompanyRoleM Exam. Person to PersonCompanyRole is a one-toone relationship and PersonCompanyRole to PersonCompanyRoleMedical Exam是一对一。 完全性在我的麻省方法中不见过去,因为当时我会有任何例外。

    [GridAction]
    public ActionResult _IncidentsGridAjaxBinding(Int32 Id)
    {
        var structures = db.sp_GetCompanyStructureDecendants(Id);
        Collection<CompanyStructureIncident> companyStructureIncidents = new Collection<CompanyStructureIncident>();

        foreach (sp_GetCompanyStructureDecendantsResult decendant in structures)
        {
            IEnumerable<CompanyStructureIncident> equipment = db.CompanyStructureIncidents.Where(r => r.CompanyStructureId == decendant.Id);
            foreach (CompanyStructureIncident companyStructureIncident in equipment)
            {
                companyStructureIncidents.Add(db.CompanyStructureIncidents.Single(p => p.Id == companyStructureIncident.Id));
            }
        }



        var model = from o in companyStructureIncidents
                    //where o.CompanyStructureId == Id
                    select new IncidentViewModel
                    {
                        Id = o.Id,
                        CompanyStructureId = o.CompanyStructureId,
                        DateOfOccurence = o.DateOfOccurence,
                        DateReported = o.DateReported,
                        Documents = o.Documents
                    };

        return View(new GridModel
        {
            Data = model
        });
    }

希望能帮助。

问题回答

我是这样说的,而不是使用OnLoad() 我这样做:

    public string Owner
    {
        get { return "PersonCompanyRoleMedicalExam"; }
    }

    public Int32 Documents
    {
        get { return sfdb.StoredFiles.Count(s => s.Owner == this.Owner && s.OwnerId == this.Id); }
    }

凭借任何途径,希望这将有助于其他人。





相关问题
LINQ to SQL as databinding source for WPF Treeview

I wonder if someone could provide a simple example of the following. (preferably in VB.Net): I have an SQL database with related tables and I am successfully using LINQ to SQL in other areas of my ...

Linq to SQL insert/select foreign/primary records

I have table A and Table B. Table B contains two columns, Name and ID. Table A contains several columns and a foreign key column pointing to B.ID called B_ID On the client side, I have all the data I ...

LINQ to SQL Dynamic Sort question

How do I code the Select clause in my LINQ satament to select column aliases so I can sort on them basically I want to accomplish this SQL statement in LINQ: select type_id as id, ...

Using a schema other than dbo in LinqToSql Designer

Is there a way to specify in a data connection or the LinqToSql Designer a schema? Whenever I go to setup a data connection for LinqToSql there doesn t seem to be anyway to specify a schema and I ...

热门标签