まず、私が何をしているのか、そこにあるのかをお見せします。 ASP.NET MVC 3の私のプロジェクト。ASP.NET MVC 3、SQL Server
これは、テーブルビジネスのモデルです。
[Table("Business")]
public class Business
{
[Key]
public long? BusinessId { get; set; }
public Int32 LegalTypeId { get; set; }
public Int16 BusinessTypeId { get; set; }
public Int64 OwnerId { get; set; }
public Int32 MainIndustryFieldId { get; set; }
public String NameNative { get; set; }
public String NameEnglish { get; set; }
public Byte[] Logo { get; set; }
public DateTime CreateDate { get; set; }
public virtual User Owner { get; set; }//It is Forign key with user table
}
[Table("User")]
public class User
{
[Key]
public Int64 UserId { get; set; }
public String UserName { get; set; }
public String LoweredUserName { get; set; }
public String FirstName { get; set; }
public String LastName { get; set; }
public String Email { get; set; }
public String LoweredEmail { get; set; }
public String Password { get; set; }
public String PasswordSalt { get; set; }
public String PasswordQuestion { get; set; }
public String PasswordAnswer { get; set; }
public Boolean IsApproved { get; set; }
public Boolean IsLocked { get; set; }
public DateTime LastActivityDate { get; set; }
public DateTime LastLoginDate { get; set; }
public DateTime CreateDate { get; set; }
public virtual Business Bussines { get; set; }
}
私は情報を追加したい:
user.Business = new Business
{
OwnerId = user.UserId,
LegalTypeId = business.LegalTypeId,
BusinessTypeId = business.BusinessTypeId,
MainIndustryFieldId = business.MainIndustryFieldId,
NameNative = business.NameNative,
NameEnglish = business.NameEnglish,
Logo = business.Logo,
CreateDate = DateTime.Now
};
ctx.SaveChanges();
私は次のエラーを取得する:データベース列のアイデンティティ仕様事業で
Cannot insert explicit value for identity column in table 'Business' when IDENTITY_INSERT is set to OFF.
を選んだがIdentity Yes
です。
誰かが何をすべきかを伝えることができます。
あなたが言ったように私がやりました。今すぐ次のエラーが発生します。 –
ReferentialConstraintの依存プロパティは、ストア生成の列にマップされます。列: 'BusinessId' –
http://stackoverflow.com/questions/4035834/cant-insert-data-to-with-ef-with-master-detail-relationship – jgauffin