示例#1
0
        public void UpdateAccountRole(int id, IEnumerable <int> roleIds)
        {
            var olds = _amsAccessor.Get <AccountRole>(i => i.AccountId == id && !roleIds.Contains(i.RoleId));

            _amsAccessor.DeleteRange(olds);
            var news = roleIds.Where(i => !_amsAccessor.Get <AccountRole>().Any(j => j.AccountId == id && j.RoleId == i))
                       .Select(i => new AccountRole {
                AccountId = id, RoleId = i
            });

            _amsAccessor.InsertRange(news);
            _amsAccessor.SaveChanges();
        }