gpt4 book ai didi

sql-server - 在数据库中建模通用关系(用 C# 表示)

转载 作者:搜寻专家 更新时间:2023-10-30 21:45:11 24 4
gpt4 key购买 nike

这很可能是你们所有性感 DBA 的一个:

我将如何有效地对关系数据库建模,从而我在“事件”表中有一个定义“运动类型”的字段?

这个“SportsType”字段可以包含指向不同运动表的链接,例如“FootballEvent”、“RubgyEvent”、“CricketEvent”和“F1 Event”。

这些运动表中的每一个都有特定于该运动的不同字段

我的目标是能够在未来根据需要一般地添加运动类型,同时将特定于运动的事件数据(字段)保存为我的事件实体的一部分。

是否可以使用 NHibernate/Entity framework/DataObjects.NET 等 ORM 来反射(reflect)这种关系?

我整理了一个快速的 C# 示例来表达我在更高层次上的意图:

public class Event<T> where T : new()
{
public T Fields { get; set; }

public Event()
{
EventType = new T();
}
}

public class FootballEvent
{
public Team CompetitorA { get; set; }
public Team CompetitorB { get; set; }
}

public class TennisEvent
{
public Player CompetitorA { get; set; }
public Player CompetitorB { get; set; }
}

public class F1RacingEvent
{
public List<Player> Drivers { get; set; }
public List<Team> Teams { get; set; }
}

public class Team
{
public IEnumerable<Player> Squad { get; set; }
}

public class Player
{
public string Name { get; set; }
public DateTime DOB { get; set;}
}

football Event code completion f1 Event code completion

最佳答案

DataObjects.Net支持开放泛型的自动映射。描述了这方面的一些细节 here .

关于sql-server - 在数据库中建模通用关系(用 C# 表示),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2546066/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com