【发布时间】:2015-10-27 16:04:29
【问题描述】:
我正在使用 AngularJS、ASP.NET、Entity Framework 和 SQL Server 开发 Web 应用程序数据库。
我想通过这种方法使用 EF 插入一些行:
public string addRow(int CaptionID, string enLang)
{
string output = "";
try
{
var Cap = new Table_Name();
string userName = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
Cap.CodeId = CaptionID;
Cap.Created = DateTime.Now;
Cap.CreatedBy = userName;
Cap.ID = "";
Cap.CodeLanguage = "en";
Cap.CodeCountry = "GB";
Cap.Caption = enLang;
_db.Entry(Cap).State = EntityState.Added;
_db.SaveChanges();
output = "Created";
}
catch (Exception ex)
{
output = ex.InnerException.Message;
}
return output;
}
此功能有效。
但是我有一个关于 NEWID() 函数的问题,我搜索了很多内容以知道如何重现相同但我不知道,我看过这个 thread 但没有。
其实我想把NEWID()赋值给Cap.ID。
P.S :我知道可以通过将SELECT NEWID() 分配给Cap.ID 来使用SQLServer,但我正在寻找一种使用EF。
【问题讨论】:
标签: c# asp.net sql-server entity-framework