내 리포지토리에 대한 기본 클래스에서 사용할 제네릭 메서드를 만들려고하고 있는데 문제가 있습니다. 여기에 방법은 ...Entity Framework의 일반 리포지토리 메서드에서 오류가 발생했습니다.
public virtual T First(System.Linq.Expressions.Expression<Func<T, bool>> where, List<string> properties)
{
IQueryable<T> query = null;
if (where != null)
{
query = _context.CreateQuery<T>(String.Format("[{0}]", typeof(T).Name.ToString())).Where(where);
}
else
{
query = _context.CreateQuery<T>(String.Format("[{0}]", typeof(T).Name.ToString()));
}
foreach (string s in properties)
{
query = query.Include(s);
}
T _result = (T)query.First();
return _result;
}
내가 코드를 실행하면 그것이 나에게이 오류 제공 :
'Company' could not be resolved in the current scope or context. Make sure that all referenced variables are in scope, that required schemas are loaded, and that namespaces are referenced correctly. Near escaped identifier, line 1, column 1.
내가이 일을 왜에 대한 아이디어가를, 난 그냥 해결하는 방법을 모른다 그것. 내 ObjectContext는 "회사"라는 개체에 대해 알지 못하기 때문에 "회사"를 알기 때문에이 작업을 수행하고 있다고 생각합니다. 이 문제를 해결하는 방법에 대한 아이디어?
오류는이 라인에서 발생 :
T _result = (T)query.First();
감사합니다!
일반적으로 엔터티 집합 이름은 복수화되어 있으므로 컨텍스트가 회사를 아는 이유입니다. 어떤 EF 버전을 사용하고 있습니까? –
버전 4를 사용하고 있습니다. 그래, 그게 작동하지 않는 이유를 추측하고 있지만 작동하도록하는 방법이 있습니까? –
쿼리가 결과를 반환하지 않는 경우 'First' 대신'FirstOrDefault'를 사용하십시오. – TheCloudlessSky