에 의해 엔티티를 검색하기위한 일반적인 방법 :엔티티 프레임 워크 4 - 나는 자신의 ID로 하나의 엔티티를 가져 오는위한 방법을 쓰고 있어요 ID
public Customer GetCustomer(int i_CustomerID)
{
return (from c in context.CustomerSet
where c.Id == i_CustomerID
select c).SingleOrDefault();
}
public Movie GetMovie(int i_MovieID)
{
return (from m in context.MovieSet
where m.Id == i_MovieID
select m).SingleOrDefault();
}
는하지만 많은 요소를 가지고 있고이 코드가 반복된다. 다음과 같은 메서드를 작성하고 싶습니다.
public T GetEntityByID<T>(int i_EntityID)
{
return (from e in context.T_Set
where e.Id == i_EntityID
select e).SingleOrDefault();
}
구현 방법이 있습니까?
비슷한 질문이 있습니다. [여기] (http://stackoverflow.com/questions/248682/create-llblgen-linq-query-dynamicly-with-strings) – Menahem