首页 > 解决方案 > 在 Query 上用另一个模型初始化模型

问题描述

我在 Web api 中使用 Dapper。我在 SQL Server DB 中有两个表,第一个称为航班,并且有两个“位置”(起点和目的地),它们是外键并分配有机场代码(TLV、IST 等),我还有另一个表“位置”包含以下列:代码、机场和国家/地区。

我的课|| 型号为:

飞行.cs:

public class Flight
{
    int ID { get; set; }

    Location StartingPoint { get; set; }

    Location Destination { get; set; }

    DateTime StartingPoint_Departure { get; set; }

    DateTime StaringPoint_Arrival { get; set; }

    DateTime Destination_Departure { get; set; }

    DateTime Destination_Arrival { get; set; }

    float Base_Price { get; set; }

    Type type { get; set; }
}

位置.cs:

public class Location
{
    public string Code { get; set; }
    
    public string Airport { get; set; }

    public string Country { get; set; }
}

现在我想用外键分配的完整类来分配飞行中的位置值。我不知道它是怎么称呼的,所以我希望你能理解。

标签: c#.net

解决方案


推荐阅读