EF核心映射到具有复杂类型的SQL视图

问题描述 投票:0回答:1

我有一个SQL View,首先需要与EF Core Code一起使用。视图看起来像这样(简化):

    Select s.Id                 
           a.City                  
           a.State
    From   Shipment s
           Join Address a
             On s.AddressId = a.Id

我希望它映射到发货清单视图的类POCO:

        public class ShipmentListView
        {
            [Key]
            public int Id { get; set; }

            public Address Address { get; set; }
        }

        public class Address
        {
            public string City { get; set; }
            public string State { get; set; }
        }

Db设置:

    public virtual DbSet<ShipmentListView> ShipmentListView { get; set; }

如何映射规范化视图,以便可以在POCO Address的上下文中重用我的ShipmentListView类>

我有一个SQL View,首先需要与EF Core Code一起使用。视图看起来像这样(简化):选择s.Id a.City a.State ...

entity-framework sql-view ef-core-2.0 ef-core-2.1
1个回答
0
投票

您可以使用下面的SQL View映射模型;

© www.soinside.com 2019 - 2024. All rights reserved.