从实体框架中的SQL存储过程结果映射实体

时间:2020-04-06 22:18:51

标签: c# sql entity-framework stored-procedures

我有一个SP,可以选择一个人的名字和姓氏,但是我将它们串联在一起,所以我在一行中收到完整的名字,这是SP的一部分:

Select SO.SubscriptionId,
               SO.ServiceOrderId,
               SO.ServiceRequestId,
               SO.CustomerAccountId,
               ...
               PD.PersonId,
               PD.FirstName + ' ' + PD.LastName, /*HERE IS THE ELEMENT I'M TALKING ABOUT*/
               SO.StartDate,
               SO.EndDate,
               SO.ModifiedBy,
               SO.ModifiedDate,
               SO.CreateDate
          From #Aux A Inner Join dbo.ServiceOrder SO
            ...
            On TD.ServiceOrderId = SO.ServiceOrderId Left Join dbo.Person PD
            On PD.PersonId = TD.DriverId

在Visual Studio中,我正在这样做:

Func<IDataRecord, ServiceOrder> f = r =>
                   {
                       return new ServiceOrder
                       {
                           SubscriptionId = r.ConvertValue<byte>("SubscriptionId"),
                           ServiceOrderId = r.ConvertValue<int>("ServiceOrderId"),
                           ServiceRequestId = r.ConvertValue<int>("ServiceRequestId"),
                           Person = new Person
                           {
                                //Here is where the name is "extracted" from the SP, but if I do it like 
                                //this, it won't work, how can I do it so I can have the full name?
                               PersonId = r.ConvertValue<int>("PersonId"),
                               Name = r.ConvertValue<string>("FirstName")
                           }
                       };
                   };

                    var query = (await db.SP<ServiceOrder>("dbo.sk_Test01", parameters, f))
                        .ToList();

0 个答案:

没有答案
相关问题