This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
Currently Lightspeed throws an error when attempting to save a TimeSpan. Would it be possible to support saving TimeSpans within the database by automatically converting to and from the number of ticks and saving it within a bigint? |
|
|
Good idea. This will be in the next release, along with support for Enums. Cheers, Andrew. |
|
|
Hi, I am still getting an error trying to save a TimeSpan property as Time(7) on SQL Server 2008. Is this supported? I am getting the following error:
Operand type clash: bigint is incompatible with time How do I get around this problem? Thanks. |
|
|
This is not currently supported: LightSpeed maps the .NET TimeSpan type to the database "big integer" type (the database's equivalent of Int64). I'm afraid you'll need to change your column to bigint. I'll have a look at whether there's anything we can do to allow you to override this behaviour but no promises... |
|
|
Okay, the next nightly build (6 Aug) will include support for custom mappings, which you can use to map a TimeSpan field to a TIME(7) column and lots of other stuff besides. What you'll need to do is apply ColumnAttribute to your backing field, with the new ConverterType option: [Column(ConverterType = typeof(SqlNativeTimeSpanConverter)] Note this is not yet supported in the designer, but I think from other threads you are hand-crafting your entities anyway so this shouldn't be an issue for you. Your converter class must support the new IFieldConverter interface. This has two methods, for conversion from the entity field type to the database value and vice versa. In the case of SQL Server TIME(7) to .NET TimeSpan conversion these are trivial: public class SqlNativeTimeSpanConverter : IFieldConverter (My test case uses a nullable column; if your column is non-nullable then you can skip the DBNull check.) Obviously the converter is only this trivial because the SqlClient classes already handle the conversion between TIME(7) and TimeSpan -- all we're doing here is wedging something in between SqlClient to make LightSpeed use the SqlClient TimeSpan value instead of doing its normal TimeSpan/Int64 conversion. So you might think that the converter is overkill. However, the same infrastructure also allows for other custom conversions, for example if you have a legacy schema where booleans are represented in the database using the strings YES and NO, and that's why we've done it this way. As always, please let us know if you have any problems getting this working or if you run into any bugs. |
|
|
Thanks for your support. Being able to customize the type mappings sounds like a great feature and flexibility to really have control on the data layer. I'm hand coding all my classes (and not using the designer) for now so I can figure out how things work under the hood. Hopefully I'll be able to answer questions from my management and other developers once I recommend LightSpeed as the tool of choice and push them to adopt it across the board. |
|