我有三个实体是相关的(帐户组帐户类别与帐户)。我正试着给数据库添加种子。下面的代码工作种子帐户组和帐户类别,但我不知道如何种子下一个水平,即帐户。
var Revenue = new AccountGroup()
{
AccountGroupName = "Revenue",
AccountCategories = new List<AccountCategory>()
{
new AccountCategory { AccountCategoryName = "Base Business Build" },
new AccountCategory { AccountCategoryName = "Contract" },
new AccountCategory { AccountCategoryName = "Other" }
}
};
_context.AccountGroups.Add(Revenue);
_context.AccountCategories.AddRange(Revenue.AccountCategories);
await _context.SaveChangesAsync();
基本业务生成类别中的帐户示例将是:项目工作、垂直销售。
任何帮助都将不胜感激。
发布于 2017-09-18 10:24:56
类似于:
foreach(AccountCategories singleCategories in Revenue.AccountCategories)
{
_context.Account.AddRange(singleCategories.Acount)
}
await _context.SaveChangesAsync();
https://stackoverflow.com/questions/46284425
复制