我正在使用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()
函数有疑问,我进行了很多搜索,以了解如何重现该函数,但我不知道,我看了这个线程,但一无所获。
实际上,我想分配NEWID()
给Cap.ID
。
PS:我知道可以通过将SQL Server分配给SELECT NEWID()
to来实现Cap.ID
,但是我正在寻找一种使用EF来实现的方法。
做就是了: Cap.ID = Guid.NewGuid();
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句