开发者

System.DateTime and Sql datetime2 in Linq2Sql (using sqlmetal)

I'd like to utilize new Sql datetime2 data type for event logging (as standard datetime has lower precision than System.DateTime causing 开发者_运维知识库data loss on storing) but when i generate the code with sqlmetal.exe i get the following warning:

db.dbml(98) : Warning DBML1008: Mapping between DbType 'DateTime2(7) NOT NULL' and Type 'System.DateTime' in Column 'CreatedOn' of Type 'Event' may cause data loss when loading from the database.

The warning disappears if i change my column definition to datetime2(2) but 2 digits precision is lower than System.DateTime can handle, right? Why? How can i suppress the warning?


You might just ignore that warning. I've checked the source of sqlmetal (using Reflector) and found this:

case SqlDbType.DateTime2:
if (scale <= 2)
  return Compatibility.Compatible;
else
  return Compatibility.DataLossFromDatabase;

However, querying a datetime2 field from a sample database returned the whole 7 digit precision.


SQLMetal is just a tool to generate your dbml file so it has no effect on runtime behaviour. But as a generation tool it may not be aware of the new datatype.

Have you tried editing the DBML yourself using an XML editor to see if you lose precision?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜