开发者

Linq to entities insertion error

I have a field name LastUpdated of type DateTime in my table and one field of type text. I am using following code:

TransactionLog lg = new TransactionLog();
lg.TransactionTypeId = 2;
**lg.Message** = "Beg开发者_运维问答inning report run for: Obligor Registry ID733058723315465243 Requesting Organization Registry ID 731099717606760920 ";// msg;
// lg.LastUpdated = DateTime.Now;

context.TransactionLogs.Add(lg);
context.SaveChanges();
long referenceNumber = lg.ID;

            return referenceNumber;

I assume that text type column can have infinite long text value. but when I try to add some more text to message, I get error. Also, DateTime in database is defined not null but a default value of GetDate() is specified. If I don't assign a date to LastUpdated column, I get error:

The conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value.
The statement has been terminated.

Please suggest me solution to this.


The size of text type column is dependent on the definition of the column in the database. So it doesn't have to accept text with any length. Different tools for creating database use different default values.

Default value for your date time column is ignored. Once you specify your property not nullable in the EF model it will always send default .NET value which is 1.1.0001. That value cannot be stored in SQL's DATETIME column. You must fill this property in your application to avoid this error.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜