【发布时间】:2016-04-13 11:40:13
【问题描述】:
使用实体框架时,我在表关系方面遇到了一些问题。
它位于 Employee 和 AspNetUser 这两个表之间。 我收到以下错误:
无法确定类型“DB.EmployeeData”和“DB.AspNetUser”之间关联的主体端。此关联的主体端必须使用关系流式 API 或数据注释显式配置。我的 poco 对象如下所示:
public partial class EmployeeData
{
public int Id { get; set; }
public string FullName { get; set; }
public string PostalCode { get; set; }
public string City { get; set; }
public double Longitude { get; set; }
public double Latitude { get; set; }
public int Age { get; set; }
public bool HighlightedNotificationsEnabled { get; set; }
public System.DateTime LastNotificationTime { get; set; }
public string StreetAndHouse { get; set; }
public string Country { get; set; }
public string Gender { get; set; }
public bool MatchingNotificationsEnabled { get; set; }
public bool NearbyNotificationsEnabled { get; set; }
public string VideoCVLink { get; set; }
public string FacebookUrl { get; set; }
public string InstagramUrl { get; set; }
public string LinkedInUrl { get; set; }
public string DriveUrl { get; set; }
public virtual AspNetUser AspNetUser { get; set; }
public virtual Translation Translation { get; set; }
}
public partial class AspNetUser
{
public AspNetUser()
{
this.AspNetUserClaims = new HashSet<AspNetUserClaim>();
this.AspNetUserLogins = new HashSet<AspNetUserLogin>();
this.AspNetRoles = new HashSet<AspNetRole>();
this.JobOffers = new HashSet<JobOffer>();
this.EmployeeQualifications = new HashSet<EmployeeQualification>();
this.NotifiedJobOffers = new HashSet<JobOffer>();
this.UserDevices = new HashSet<UserDevice>();
this.Applications = new HashSet<Application>();
}
public string Id { get; set; }
public string Email { get; set; }
public bool EmailConfirmed { get; set; }
public string PasswordHash { get; set; }
public string SecurityStamp { get; set; }
public string PhoneNumber { get; set; }
public bool PhoneNumberConfirmed { get; set; }
public bool TwoFactorEnabled { get; set; }
public Nullable<System.DateTime> LockoutEndDateUtc { get; set; }
public bool LockoutEnabled { get; set; }
public int AccessFailedCount { get; set; }
public string UserName { get; set; }
public string JobnetOrganisationId { get; set; }
public virtual ICollection<AspNetUserClaim> AspNetUserClaims { get; set; }
public virtual ICollection<AspNetUserLogin> AspNetUserLogins { get; set; }
public virtual ICollection<AspNetRole> AspNetRoles { get; set; }
public virtual EmployerData EmployerData { get; set; }
public virtual EmployeeData EmployeeData { get; set; }
public virtual ICollection<JobOffer> JobOffers { get; set; }
public virtual ICollection<EmployeeQualification> EmployeeQualifications { get; set; }
public virtual ICollection<JobOffer> NotifiedJobOffers { get; set; }
public virtual ICollection<UserDevice> UserDevices { get; set; }
public virtual ICollection<Application> Applications { get; set; }
}
我已经用谷歌搜索了这个并尝试使用数据注释和流畅的 API 来修复它,但我无法摆脱错误。
谁能指出我做错了什么?
谢谢:)
【问题讨论】:
-
您可以为这两个实体添加您当前的映射吗?
标签: database entity-framework data-annotations ef-fluent-api