【发布时间】:2019-09-20 20:19:02
【问题描述】:
我正在使用 EF DbSet<FiveMinStockHistory>。现在,我需要一个代码 sn-p,展示如何实现 EF6+ 方法 DbContext.OnModelCreating(DbModelBuilder modelBuilder) 来填充代码优先数据库。我找不到任何好的例子。
public class FiveMinStockHistory
{
public int Id { get; set; }
public Dictionary<string, string> Meta_Data { get; set; }
public Dictionary<string, TimeSeries> Lhocv { get; set; }
}
public class TimeSeries
{
public decimal Open { get; set; }
public decimal High { get; set; }
public decimal Low { get; set; }
public decimal Close { get; set; }
public double Volume { get; set; }
}
谢谢!!!
【问题讨论】:
-
您可以编写一个静态 DbInitializer 类并从 Startup.cs 或 Program.cs 调用它。
-
填充什么?有很多播种数据库的例子。如果您找不到任何示例,可能是因为您找不到任何使用
Dictionary导航属性的代码,仅仅是因为它们不受支持。 -
我尝试过类似:stackoverflow.com/questions/14779740/… 的求和,但让 Dbcontext 进行序列化和反序列化,并在需要时创建一个表。
-
看起来类对象是上面给出的序列化的最佳位置。
标签: c# entity-framework