ASP.Net Core - готовая загрузка с хранимой процедурой вместо включения - PullRequest
0 голосов
/ 31 мая 2018

Есть ли способ реализовать активную загрузку, если хранимая процедура возвращает набор результатов, который затем может быть автоматически привязан к родительскому объекту данных и его связанным объектам данных?В настоящее время я пытаюсь сделать это с ASP.Net Core 2.0

Пример:

Для этих объектов данных:

public class Address 
{
    public int Id {get;set;}
    public string Street1 {get;set;}
    public string Street2 {get;set;}
    public string City {get;set;}
    public string Region {get;set;}
    public string PostalCode {get;set;}
    public string Country {get;set;}
}
public class Product
{
    public int Id {get;set;}
    public string Name {get;set;}
    public decimal Price {get;set;}  
}
public class Customer
{
    public int Id {get;set;}
    public string FirstName {get;set;}
    public string LastName {get;set;}
    public Address ShippingAddress {get;set;}
    public Address BillingAddress {get;set;}
    public List<Product> Products {get;set;}
}

может ли контроллер сделать вызов, который возвращаетмногие клиенты, похожие на:

var recordSet = dbContext.Set<Customer>().FromSql("EXEC dbo.[GetCustomerInfo] @TokenDtime={0}", tokenDtime);

где dbo. [GetCustomerInfo] содержит что-то вроде следующего:

Запрос A - Присоединение Bssic:

SELECT 
    c.[Id]           [CustomerId]                        ,
    c.[FirstName]    [CustomerFirstName]                 ,
    c.[LastName]     [CustomerLastName]                  ,
    sa.[Id]          [CustomerShippingAddressId]         ,
    sa.[Street1]     [CustomerShippingAddressStreet1]    ,
    sa.[Street2]     [CustomerShippingAddressStreet2]    ,
    sa.[City]        [CustomerShippingAddressCity]       ,
    sa.[PostalCode]  [CustomerShippingAddressPostalCode] ,
    sa.[Country]     [CustomerShippingAddressCountry]    ,
    sb.[Id]          [CustomerShippingAddressId]         ,
    sb.[Street1]     [CustomerShippingAddressStreet1]    ,
    sb.[Street2]     [CustomerShippingAddressStreet2]    ,
    sb.[City]        [CustomerShippingAddressCity]       ,
    sb.[PostalCode]  [CustomerShippingAddressPostalCode] ,
    sb.[Country]     [CustomerShippingAddressCountry]    ,
    p.[Id]           [ProductId]                         ,
    p.[Name]         [ProductName]                       ,
    p.[Price]        [ProductPrice]
FROM
    [Customer] c
    LEFT OUTER JOIN
    [Address] sa ON c.[ShippingAddressId] = sa.[Id]
    LEFT OUTER JOIN
    [Address] sb ON c.[BillingAddressId] = sb.[Id]
    LEFT OUTER JOIN
    [CustomerProduct] cp ON c.[Id] = cp.[CustomerId]
    LEFT OUTER JOIN
    [Product] p ON cp.[ProductId] = p.[Id]
WHERE
    c.[TokenDtime] >= @TokenDtime

Запрос B- Несколько наборов записей:

SELECT 
    c.[Id]           [CustomerId]                        ,
    c.[FirstName]    [CustomerFirstName]                 ,
    c.[LastName]     [CustomerLastName]                  ,
    sa.[Id]          [CustomerShippingAddressId]         ,
    sa.[Street1]     [CustomerShippingAddressStreet1]    ,
    sa.[Street2]     [CustomerShippingAddressStreet2]    ,
    sa.[City]        [CustomerShippingAddressCity]       ,
    sa.[PostalCode]  [CustomerShippingAddressPostalCode] ,
    sa.[Country]     [CustomerShippingAddressCountry]    ,
    sb.[Id]          [CustomerBillingAddressId]          ,
    sb.[Street1]     [CustomerBillingAddressStreet1]     ,
    sb.[Street2]     [CustomerBillingAddressStreet2]     ,
    sb.[City]        [CustomerBillingAddressCity]        ,
    sb.[PostalCode]  [CustomerBillingAddressPostalCode]  ,
    sb.[Country]     [CustomerBillingAddressCountry]     
FROM
    [Customer] c
    LEFT OUTER JOIN
    [Address] sa ON c.[ShippingAddressId] = sa.[Id]
    LEFT OUTER JOIN
    [Address] sb ON c.[BillingAddressId] = sb.[Id]
WHERE
    c.[TokenDtime] >= @TokenDtime        

SELECT 
    c.[Id]           [CustomerId]                        ,
    p.[Id]           [ProductId]                         ,
    p.[Name]         [ProductName]                       ,
    p.[Price]        [ProductPrice]
FROM
    [Customer] c
    LEFT OUTER JOIN
    [CustomerProduct] cp ON c.[Id] = cp.[CustomerId]
    LEFT OUTER JOIN
    [Product] p ON cp.[ProductId] = p.[Id]
WHERE
    c.[TokenDtime] >= @TokenDtime        
...