Frage

Ich mag Datums- und Uhrzeitwerte speichern, mit dem datetime2 Typ in SQL Server CE 3.5.

Wenn dies möglich ist, wie würde ich meine Entität Datenmodell ändern? Ich habe versucht, es manuell bearbeiten und Visual Studio verweigert es danach in dem Designer zu zeigen.

War es hilfreich?

Lösung

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)

Andere Tipps

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.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top