[英]How do I navigate related entities from a stored procedure that is mapped to an entity
I have a complicated full-text search stored procedure that I have mapped to return an entity type.我有一个复杂的全文搜索存储过程,我已将其映射为返回实体类型。 It won't allow me to navigate the references in the result though:
但是,它不允许我导航结果中的引用:
using (MyEntities kb = new MyEntities())
{
var results = from customer in kb.SearchCustomers("blabla") select new
{
CustomerName = customer.LastName + ", " + customer.FirstName,
RegionName = customer.Region.Name
};
}
This is throwing a null reference exception when referring to the customer.这是在引用客户时抛出空引用异常。
We should check LastName and FirstName first.我们应该首先检查姓氏和名字。 I think there are customers who don't have FirstName or Lastname.
我认为有些客户没有名字或姓氏。
using (MyEntities kb = new MyEntities())
{
var results = from customer in kb.SearchCustomers("blabla") select new
{
if(customer.LastName != null && customer.FirstName != null)
{
CustomerName = customer.LastName + ", " + customer.FirstName,
RegionName = customer.Region.Name
}
};
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.