我使用Code First EF创建Asp.Net Mvc4应用程序。我创建了我的模型,现在我想从数据库中获取关系信息。我为这个信息写了get方法如下:
public IQueryable<Invoice.Model.Invoice> Invoices
{
get
{
return context.Invoices.Include("InvoiceItems").Include("InvoiceStatus").Include("BankAccount").Include("TaxType").Include("Contract");
}
}
然后我在我的操作中使用这个属性,但关系信息suach为InvoiceStatus返回null,如何解决这个问题? 提前致谢。 我使用发票 IQueryable ,如下所示
public IQueryable<Company> GetMyCompaniesByUserId(Guid userId)
{
var obj = context.Companies.Include("BankAccounts");
if (obj.Count() != 0)
{
Company com = obj.First();
}
var companeies = from c in obj
from myc in context.MyCompanies
where c.IsDelete == false && myc.UserId == userId && c.CompanyId == myc.CompanyId
select c;
return companeies;
}