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
|
I have a simple (but potentially large) SQLite database with two tables, each of which has a primary key called 'timestamp' with type DateTime. My application logs a set of weather data at 1-minute intervals, so this seemed the logical choice (but I am no expert in database design). With the Entity Data Model, all of my columns are mapped automatically, including the timestamp. With Lightspeed, the timestamp column is not mapped. If I understand the documentation correctly, this is because Lightspeed requires my primary key to be an integer called 'id'. Have I understood this correctly? Steve |
|
|
If you're using the LightSpeed designer, then your primary key must be an integer (Int32), big integer (Int64), string or GUID. The column *doesn't* have to be called Id, but if it's not called Id, you need to tell LightSpeed the name using the entity Identity Column Name setting. The property in the entity type *is* always called Id -- that's not configurable (Identity Column Name changes the database mapping, not the entity property name.) Writing your entities by hand in C# or Visual Basic gives you a bit more flexibility: you can have any type you want as an ID by specifying that type when you derive from Entity<TId>. So your entities would derive from Entity<DateTime> rather than Entity<int> or Entity<Guid>. And you can map the column name using TableAttribute(IdColumnName="MyPKName"). However, LightSpeed doesn't provide a built-in way to generate IDs of type DateTime, so you would need to override Entity.GeneratedId() to return the desired DateTime ID. Our recommendation if you have control over the database is to use a surrogate key -- an integer or bigint key that has no business meaning -- and reserve business-meaningful data like timestamps for "normal" columns. This will allow you to use the designer and to take advantage of LightSpeed's built-in identity generators like KeyTable. But if you want to keep the DateTime as the PK then it is possible as described above, just less convenient. |
|