我正在开发一个仪表板应用程序,我将各种数据库中的数据导入到新的ASP.Net MVC应用程序/数据库中。我想维护源系统的数据结构。有没有办法将PK从导入的数据源分配到我的应用程序中的模型的PK?基本上模仿源系统数据结构?
我正在使用实体框架代码第一种方法来构建数据库。以下是目前的型号。
public class PageStats
{
public int PageStatsId { get; set; }
public string Metric { get; set; }
public string PageTitle { get; set; }
public DateTime? Date { get; set; }
public string Country { get; set; }
public int PageViews { get; set; }
public int UniquePageViews { get; set; }
public double AvgSessionDuration { get; set; }
public double AvgTimeOnPage { get; set; }
public string TopicSectionId { get; set; }
public virtual TopicSection TopicSection { get; set; }
}
public class TopicSection
{
public int Id { get; set; }
public string TopicSectionId { get; set; }
public string TopicSectionName { get; set; }
}
答案 0 :(得分:0)
如果您使用的是SQL Server:
当你创建新的'数据库表,不要在PK列上包含标识定义。这将允许您将CSV文件中的数据加载到新表中,而无需SQL为PK字段分配新值。
如果您正在使用EF EDMX设计表格,请选择TopicSection.Id字段,然后关闭标识字段定义(将" Entity Key"参数设置为false)。