本文介绍了奇怪的表键导致代码首先出现在现有DB中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想我需要查看映射类,但是我认为我的问题是什么。我有一个POCO类"种族"使用外部钥匙的位置/赞助商和会员

I think I need to look up the mapping classes, but heres what i beleive is my problem. I have a POCO class "Race" with external keys for location/Sponsor and member

因此有虚拟的位置/赞助商等

consequently there are virtual Location/Sponsor etc

但是每个人的ID ... Race.rLocationID需要映射到Location.LocationID

however the id of each.. Race.rLocationID needs to map to Location.LocationID

race.rSponsorID => Sponsor.SponsorID

race.rSponsorID =>Sponsor.SponsorID

Race.rDirector => member.mMemberID

Race.rDirector =>member.mMemberID

我认为: 这给了我内部错误:

I think: this gives me the internal error:

{"无效的列名'MembermMemberID'.\ \\\
无效的列名'LocationLocationID'.\\ n无效的列名'SponsorSponsorID'。"}

{"Invalid column name 'MembermMemberID'.\r\nInvalid column name 'LocationLocationID'.\r\nInvalid column name 'SponsorSponsorID'."}


推荐答案


public class Race
{
  public int RaceId { get; set; }
    
  [Column(Name = "rLocationID")]
  public int LocationID { get; set; }

  [Column(Name = "rSponsorID")]
  public int SponsorID { get; set; }

  [Column(Name = "rDirector")]
  public int DirectorId { get; set; }
            
  public virtual Location Location { get; set; }        
  public virtual Sponsor Sponsor { get; set; }
    
  [ForeignKey("DirectorId")]
  public virtual Member Director { get; set; }
}

public class Location
{
  public int LocationID { get; set; }   
}

public class Sponsor
{
  public int SponsorID { get; set; }
}

public class Member
{
  public int MemberID { get; set; }
}


这篇关于奇怪的表键导致代码首先出现在现有DB中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 20:39