-1
나는 이런 종류가있다.EF 복잡한 수업이 나를 null로 받고
public class User
{
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Email { get; set; }
public IList<Role> Roles { get; set; }
public virtual Branch Branch { get; set; }
public string Password { get; set; }
}
public class Branch
{
public int Id { get; set; }
public string Name { get; set; }
public string Location { get; set; }
public virtual Region Region { get; set; }
}
문제는 내가 사용자를 리포지토리 계층 메서드로 매개 변수로 전달할 때 분기 속성이 null에 나타나는 것입니다. 저장소에 도착하기 전에 null이 아닌지 확인했습니다. 나는 직렬화와 함께 뭔가 생각하지만, 그것을 수정하는 방법을 모르겠습니다. 사전에
감사합니다!
public readonly IDbSet<T> DbSet;
public IEnumerable<T> Find(Expression<Func<T, bool>> predicate, string sortColumn = null, bool sortDirection = true, params string[] includes)
{
if (sortColumn == null)
{
var resultSet = GetDbSet(includes).Where(predicate);
resultSet.ForEachAsync(e => Detach(e)).Wait();
return resultSet;
}
else
return OrderByField<T>(GetDbSet(includes).Where(predicate), sortColumn, sortDirection);
}
private IQueryable<T> GetDbSet(params string[] includes)
{
IQueryable<T> resultSet = DbSet;
foreach (string include in includes)
resultSet = resultSet.Include(include);
return resultSet;
}
private T Detach(T entity)
{
System.Diagnostics.Contracts.Contract.Requires(entity != null);
var entry = Context.Entry(entity);
entry.State = System.Data.Entity.EntityState.Detached;
return entity;
}
개체를 가져 오는 위치와 전달 방법을 코드에 표시하십시오. –
세션 변수에 저장하면 동일한 문제가 있다는 점은 저장소와 관련이 없다고 생각합니다. – mariaoialvarez
담당자에게서 오브젝트를 가져 오는 코드를 표시하지 않으면 나는 당신을 도울 수 없습니다. –