简体   繁体   English

如何从映射到实体的存储过程导航相关实体

[英]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.

相关问题 如何删除与特定实体相关的所有实体? - How do I delete all the entities related to a specific entity? 我如何获得一个实体及其所有相关实体 - How do I get an entity and all of its related entities 如何使用实体框架从数据库视图加载相关实体? - How do I load related entities from a database view using entity framework? 使用非映射实体从Db Context调用存储过程 - Calling Stored Procedure From Db Context with an non mapped entity 实体框架:如何运行存储过程并返回值? - Entity Framework: how do I run a stored procedure and return a value? 如何从存储过程结果实体框架创建列表 - How do I create a list from stored procedure results Entity Framework 如何获得在linq中嵌套到实体的相关实体? 调查问题,子问题和选项 - How do I get related entity nested in linq to entities? Survey questions, subquestions, and options 如何使用 Entity Framework 和 .NET 5.0 构建查询以在相关表中查找不匹配的实体? - How do I contruct a query to find unmatched entities in related table with Entity Framework and .NET 5.0? 在实体框架中使用存储过程,如何获取实体以填充其导航属性? - Using a stored procedure in entity framework, how do I get the entity to have its navigation properties populated? 使用实体框架代码优先方法,如何创建一个具有相关实体列表作为子属性的实体? - Using Entity Framework Code First approach, how do I create an entity that has a list of related entities as a child property?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM