0
我有一個名爲Articles的表的數據庫。LinqToSql調用默認方法
該表存儲文章並具有字段CDTimeStamp。 的CDTimestamp場變了這個樣子,所以它總是具有正確的創建日期:
ALTER TABLE [dbo].[Artikel] ADD CONSTRAINT [DF_Artikel_CDTimeStamp] DEFAULT (getdate()) FOR [CDTimeStamp]
GO
所以,如果我嘗試添加了一篇文章,我得到一個錯誤。 文章中加入這樣的:
public void AddArticle()
{
this.Open();
Article article = new Article();
article.Description = "";
article.ArticleNr = GetArticleNumber();
article.Barcode = GetBarcode(); //EAN
article.Branch = GetBranch(); // 3digit number
article.Company = GetCompany(); // 1 or 2
article.Preis = GetPrice();
article.PreisNew = GetNewPrice();
//article.CDTimeStamp = DateTime.Now;
_OutDataContext.Artikel.InsertOnSubmit(article);
try
{
this.Submit();
}
catch (Exception e)
{
throw;
}
this.Close();
}
我得到的錯誤是:
SQLDATETIME溢出。必須介於1/1/1753 12:00:00 AM和 12/31/9999 11:59:59 PM之間。
如果我取消註釋//article.CDTimeStamp = DateTime.Now;
創建並插入DateTime,但應該插入getdate()默認值,而不是我在程序中創建的值。 我的問題是: 是否有一個配置條目或類似的東西,使默認功能的調用?數據庫字段可能不爲null。
P.S. 我不太清楚如何調用這個問題,所以如果你知道更正確的標題,請隨時編輯它。
非常簡單的答案謝謝。僅供參考在dbml資源管理器中,我可以設置一個名爲「Auto Generated Value」的屬性,然後生成IsDbGenerated屬性。 – Bongo