3 回答

TA貢獻1773條經(jīng)驗 獲得超3個贊
使用擴展方法。將NameOfContext替換為對象上下文的名稱。
public static class Extensions{
public static IQueryable<Company> CompleteCompanies(this NameOfContext context){
return context.Companies
.Include("Employee.Employee_Car")
.Include("Employee.Employee_Country") ;
}
public static Company CompanyById(this NameOfContext context, int companyID){
return context.Companies
.Include("Employee.Employee_Car")
.Include("Employee.Employee_Country")
.FirstOrDefault(c => c.Id == companyID) ;
}
}
然后你的代碼變成了
Company company =
context.CompleteCompanies().FirstOrDefault(c => c.Id == companyID);
//or if you want even more
Company company =
context.CompanyById(companyID);
- 3 回答
- 0 關(guān)注
- 2809 瀏覽
添加回答
舉報