尝试针对角色组保存角色列表但是没有插入第三个表?任何人都可以帮助我错过的东西吗?
public async Task<string> AssignSave(List<ApplicationRoles> Roles , int Id)
{
using (var context = new ApplicationDbContext())
{
var rolegroup = await (from _rolegroup in context.RoleGroup.Include(x => x.Roles)
where _rolegroup.FK_CompanyProfile_ID.Equals(CompanyId) && _rolegroup.Id.Equals(Id)
select _rolegroup).FirstOrDefaultAsync();
context.Entry<RoleGroup>(rolegroup).State = EntityState.Modified;
rolegroup.Roles.Clear();
foreach (var role in Roles)
{
var _role = await context.ApplicationRoles.FindAsync(role.Id);
rolegroup.Roles.Add(_role);
context.Entry<ApplicationRoles>(_role).State = EntityState.Modified;
}
int y = await (context.SaveChangesAsync());
if (y > 0)
return Success;
else
return Error;
}
}