문제

I would like to store DateTime values using the datetime2 type in SQL Server CE 3.5.

If this is possible, how would I change my entity data model? I've tried editing it manually and Visual Studio refuses to show it in the designer afterwards.

도움이 되었습니까?

해결책

datetime2 does not exist is SQL Server Compact, in order to save datetime2 values, you must save in a nvarchar(27) value of the form 'YYYY-MM-DD hh:mm:ss.nnnnnnn' (see http://msdn.microsoft.com/en-us/library/ms171931.aspx)

다른 팁

If you take care about size of your database (especially if you've got indexes on this field), you can use a different approach.

Keep in the database two fields datetime (for YYYY-MM-DD hh:mm:ss) and smallint (for milliseconds). And join them to get a proper DateTime before displaying in UI.

In this case size of these fields will be 10 bytes (according to this source, 8 bytes of datetime + 2 bytes for smallint). Size of nvarchar(27) is 54 bytes.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top