如何解决我想将商店模型与用户模型联系起来
我想在商店和用户之间建立联系 因为我要根据用户显示商店索引 但是当我这样做时,这个问题就出现了
INSERT语句与FOREIGN KEY约束“ FK_dbo.AspNetUsers_dbo.Stores_StoreID”冲突。在数据库“ FAPDB_73bf5fda8e4e4f42bc46f8f5257d6e6c”的表“ dbo.Stores”的“ ID”列中发生了冲突。 该声明已终止。
所以我将StoreID添加到了viewmodel中:
public class RegisterViewModel
{
[Required]
[MinLength(5,ErrorMessage = "The lowest number of characters 5")]
[Display(Name = "User Name")]
public string UserNAme { get; set; }
[Required]
[EmailAddress]
[Display(Name = "Email")]
public string Email { get; set; }
[Required]
[Display(Name = "User type")]
public string UserType { get; set; }
[Display(Name = "Store")]
public int StoreID { get; set; }
[Required]
[StringLength(100,ErrorMessage = "The {0} must be at least {2} characters long.",MinimumLength = 6)]
[DataType(DataType.Password)]
[Display(Name = "Password")]
public string Password { get; set; }
[DataType(DataType.Password)]
[Display(Name = "Confirm password")]
[Compare("Password",ErrorMessage = "The password and confirmation password do not match.")]
public string ConfirmPassword { get; set; }
}
我将其添加到ApplicationUser中:
public class ApplicationUser : IdentityUser
{
public string UserType { get; set; }
public Nullable<int> StoreID { get; set; }
[ForeignKey("StoreID")]
public virtual Store store { get; set; }
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager)
{
// Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
var userIdentity = await manager.CreateIdentityAsync(this,DefaultAuthenticationTypes.ApplicationCookie);
// Add custom user claims here
return userIdentity;
}
}
并在视野中:
<div class="form-group">
@Html.LabelFor(m => m.StoreID,new { @class = "col-md-2 control-label" })
<div class="col-md-10">
@Html.DropDownList("StoreIN",null,htmlAttributes: new { @class = "form-control" })
</div>
</div>
,我添加了迁移 那么怎么了?!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。