实体框架映射异常

时间:2011-11-11 19:38:57

标签: c# entity-framework

我正在学习实体框架,所以我创建了一个带有两个表的简单模型,添加适当的类,我正在尝试编写一个简单的仓库,但应用程序粉碎了我的仓库:(

MyEntityPOCO是我的控制台App项目的名称:)

链接到数据库vizualisation http://wstaw.org/w/LrL/

这是我的回购代码



    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Data.Objects;

    namespace MyEntityPOCO
    {
         public class Entities : ObjectContext
         {
              private ObjectSet _contacts;
              private ObjectSet _addresses;

              public Entities()
                   : base("name=MyEntities", "MyEntities")
              {
                   _contacts = CreateObjectSet();
                   _addresses = CreateObjectSet();
              }

              public ObjectSet Contacts
              { get { return _contacts; } }


              public ObjectSet Addresses
              { get { return _addresses; } }

         }

    }




这是关于例外的详细信息。



    {"Mapping and metadata information could not
     be found for EntityType 'MyEntityPOCO.Contact'."}

这是联系



    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Collections;

        namespace MyEntityPOCO
        {
             public class Contact
             {
                  public int ContactID { get; set; }
                  public string FirstName { get; set; }
                  public string LastName { get; set; }
                  public ICollection Addresses { get; set; }
             }
        }

地址



    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    namespace MyEntityPOCO
    {
         public class Address
         {

              public int AddressID { get; set; }
              public string Street { get; set; }
              public string City { get; set; }
         }
    }

这是我的App.Config



    
    
      

      
    

这是来自模型属性的连接字符串



    metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string="data source=COMPAL\COMPALSERWER;initial catalog=MyBase1;integrated security=True;multipleactiveresultsets=True;App=EntityFramework"

这是来自服务器资源管理器的连接字符串



    Data Source=COMPAL\COMPALSERWER;Initial Catalog=MyBase1;Integrated Security=True

来自服务器资源管理器的

和提供程序

.NET Framework Data Provider for SQL Server

1 个答案:

答案 0 :(得分:0)

您的联系人的“地址”是......的集合?您必须声明它是EF的Address对象集合才能正确进行映射。

byear