【发布时间】:2017-08-07 06:41:48
【问题描述】:
从昨天开始,我一直在与那个奇怪的错误作斗争。本地主机部署工作正常,但在 Azure 上部署几个小时后,我得到了
一个或多个实体的验证失败。有关详细信息,请参阅“EntityValidationErrors”属性。
当我进入我的控制器注册操作时会发生这种情况:
[AllowAnonymous]
public ActionResult Register()
{
Wallet stockMarketWallet = walletRepository.GetMarketWallet(); // here it comes
RegisterViewModel vm = new RegisterViewModel();
vm.UserStocks = new List<UserStockViewModel>();
foreach (UserStock stock in stockMarketWallet.OwnedStocks)
{
vm.UserStocks.Add(new UserStockViewModel {
StockId = stock.StockId,
Code = stock.Stock.Code
});
}
return View(vm);
}
内部错误详细信息表明 UserApplications 不是唯一用户名正在上升 ValidationError。
WalletRepository
public class WalletRepository : IWalletRepository
{
private ApplicationContext context;
public WalletRepository()
=> context = ApplicationContext.Create();
public Wallet GetMarketWallet()
{
string stockMarketUserName = ConfigurationManager.AppSettings["StockMarketUsername"];
return context.Wallets.FirstOrDefault(w => w.ApplicationUser.UserName.Equals(stockMarketUserName));
}
...
}
}
钱包
public class Wallet
{
[Key, ForeignKey("ApplicationUser")]
public string WalletId { get; set; }
public decimal Founds { get; set; }
public virtual IList<UserStock> OwnedStocks { get; set; }
public virtual ApplicationUser ApplicationUser { get; set; }
public Wallet()
{
OwnedStocks = new List<UserStock>();
}
...
}
应用程序用户
public class ApplicationUser : IdentityUser
{
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager)
{
var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
return userIdentity;
}
public virtual Wallet Wallet { get; set; }
}
在将 Azure 数据库克隆到 localhost 后,对我来说更陌生的是它也可以正常工作。
【问题讨论】:
-
尝试检查验证错误。见@wizzardz 答案:stackoverflow.com/questions/17020947/…
-
我写了,这是唯一的用户名验证错误,但是在阅读过程中怎么会出现呢?
标签: c# asp.net-mvc azure entity-framework-6