【发布时间】:2018-02-07 18:03:45
【问题描述】:
我有一个连接到 EF 数据库的 mvc5 应用程序。此数据库中的某些字段旨在按照 SQL 中的声明自动生成,但在 MVC 中使用和插入记录时,GUID 仅包含所有记录的值 0。我该如何解决这个问题?任何帮助将不胜感激。谢谢。
模型类:
public partial class Store
{
public int StoreID { get; set; }
public int CustomerID { get; set; }
public string StoreName { get; set; }
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public System.Guid StoreUID { get; set; }
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int StoreNumber { get; set; }
public string StoreLogo { get; set; }
public string StoreLogoPath { get; set; }
public string StoreAddress { get; set; }
public string StoreCity { get; set; }
public string StoreRegion { get; set; }
public string StoreCountry { get; set; }
public virtual Customer Customer { get; set; }
}
StoreUID 和 StoreNumber 都应该是自动生成的字段。下面是插入新商店时的示例,但是目前,storeNumber 和 StoreUID 都只返回 0。
【问题讨论】:
标签: sql asp.net-mvc entity-framework auto-generate