[英]Entity framework mapping exception
我正在學習Entity Framework,所以我創建了一個帶有兩個表的簡單模型,添加了適當的類,並嘗試編寫一個簡單的存儲庫,但是應用程序在我的存儲庫中崩潰了:(
MyEntityPOCO是我的控制台應用程序項目的名稱:)
鏈接到數據庫虛擬化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
您聯系人的“地址”是...的集合? 您必須聲明它是EF地址對象的集合才能正確執行映射。
public class Contact
{
public int ContactID { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public ICollection<Address> Addresses { get; set; }
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.