سؤال

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