خرید بک لینک

Vote count: 0

I'm trying to implement one-to-many Update method using EF6 i can added i caot update,update caot updates to database The following is entiy and add/update method,How can I fix it?

public class Role : Entity
{
    public string RoleName { get; set; }

    public string Description { get; set; }

    public virtual ICollection<Function> Functions { get; set; }

    public virtual ICollection<User> Users { get; set; }
}

public void Add(Role role, long[] userIds, long[] functionIds)
    {
        if (userIds != null && userIds.Length > 0)
            role.Users = _userRepository.GetAll().Where(t => userIds.Contains(t.Id)).ToList();
        if (functionIds != null && functionIds.Length > 0)
            role.Functions = _functionRepository.GetAll().Where(t => functionIds.Contains(t.Id)).ToList();
        _roleRepository.Insert(role);
        _unitOfWork.Commit();
    }`
public void Modify(Role role, long[] userIds, long[] functionIds)
    {
        var roleData = _roleRepository.GetAll().Include(t => t.Users).Include(t => t.Functions).FirstOrDefault(t => t.Id == role.Id);
        roleData.RoleName = role.RoleName.Trim();
        roleData.Description = role.Description;
        roleData.Users.Clear();
        roleData.Functions.Clear();
        if (userIds != null && userIds.Length > 0)
            _userRepository.GetAll().Where(t => userIds.Contains(t.Id)).ToList().ForEach(x => roleData.Users.Add(x));
        if (functionIds != null && functionIds.Length > 0)
           _functionRepository.GetAll().Where(t => functionIds.Contains(t.Id)).ToList().ForEach(x => roleData.Functions.Add(x));
        _roleRepository.Update(roleData);
        _unitOfWork.Commit(
    }`
public virtual TEntity Update(TEntity entity)
    {
        _entities.Entry(entity).State = System.Data.Entity.EntityState.Modified;
        retu entity;
    }`
public virtual TEntity Insert(TEntity entity)
    {
        retu _dbset.Add(entity);
    }`

asked 1 min ago

برچسب: نویسنده: استخدام کار تاريخ: شنبه 21 فروردين 1395 ساعت: 10:28

صفحه بندی