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
|
Hi, I have an exisiting table with an "ID" column and am struggling to gracefully override the Id entity property convention so Lightspeed uses the ClientUID. (If I change the Id property to IdCode or similar in the model everything works as expected) CREATE TABLE [dbo].[Client]( When I create an lsmodel with a Client entity public partial class Client : Entity<System.Guid> I have a custom naming strategy loaded via the config file (which I have confirmed is getting called using the debugger) that overides the Id. ..... string INamingStrategy.GetIdColumnName(string tableName, string className, string defaultName) ..... When I build the code I get this warning ( I appreciate why this is happening when I look at the underlying Lightspeed class) Warning 1 'MindscapeTrial.Client.Id' hides inherited member 'Mindscape.LightSpeed.Entity<System.Guid>.Id'. Use the new keyword if hiding was intended. C:\Projects\PocketVouchers\MindscapeTrial - Copy\MindscapeTrial\PocketVouchers.cs 67 19 MindscapeTrial When I perform an insert it fails and using SQL profiler to look at the generated code you can see that my Id is also being replaced with ClientUID. exec sp_executesql N'INSERT INTO Client Is there a preferred way of handling this situation? Thanks Bryn |
|
|
LightSpeed declares an Id property in the Entity<T> base class, so you must not declare an Id property of your own. Instead, you must declare a property with a different name and then map that to the Id column in the database. To do this in the designer, rename your Id property to, say, Identifier, and set its Column Name to Id. (You can right-click the property and choose Refactor > Rename > Keep old name as column name to do this automatically.) Since you are using the designer you may also find it more convenient to set the entity's Identity Column Name to ClientUID rather than using a naming strategy -- the designer doesn't know about the runtime naming strategy, so using Identity Column Name will play nicer with designer-database synchronisation. |
|
|
Thanks Ivan, In the lightspeed entity the Id has become IdCode and I have removed the Id column code from the NamingStrategy The exisiting database uses the convention of an integer versioning column called "Version". To overide the convention for the name of optimisitic versioning column, I modified the NamingStrategy string INamingStrategy.GetLockVersionColumnName(string tableName, string className, string defaultName) After doing that I found that I got duplicate column names in the generated SQL I could see in Query profiler. exec sp_executesql N'INSERT INTO Client Is the preferred way of fixing this to change the "Generation" property of the Version property of the entity? |
|
|
I'm assuming that you have Optimistic Concurrency Checking set to true as well as having the Version property, is that right? If so, changing the Version property's Generation setting to None as you suggest will indeed work. However, if you expect the model to change then it is not ideal because it won't play nicely with designer-database synchronisation (because the designer would be trying to map the Optimistic Concurrency Checking flag to a column named LockVersion). If this isn't a concern, then I think you might as well in fact delete the Version property -- the only reason to have a property with Generation=None is to have it participate in database sync. If it is a concern, there are two options: 1. Set Optimistic Concurrency Checking to False. Then rename the Version property to LockVersion, and set its Column Name to Version. This effectively manually creates the LockVersion property (which OCC was previously creating for you), but maps it to the Version column so that the designer doesn't look for a LockVersion column. (Versioning is triggered by the presence of a LockVersion field, so all OCC is doing under the surface is creating that field. Creating it manually instead of via the OCC flag therefore has exactly the same results.) 2. Tell the designer also to use a custom naming strategy. This is a hidden option because it's a bit fiddly to use -- see http://www.mindscape.co.nz/forums/Thread.aspx?ThreadID=3486 if you're feeling brave! Hope this helps! |
|
|
Hi, Yes, optimistic concurrency checking was turned on and the version column was present. I tried option 1 by renaming the Version property in the entity to LockVersion, manually setting the name of that properties DB column to Version and disabling OCC for the Entity. But when I tried in insert a new record the insert failed with "Invalid column name LockVersion" From SQL Profiler exec sp_executesql N'INSERT INTO Client From class file [Column("Version")] Will try option 2 as well. Bryn |
|
|
Did you also turn off your naming strategy? It looks like we have a bug where Column Name is not respected by the SQL generator for "special" properties like LockVersion, so you would need to keep the naming strategy in place. (Column Name *is* respected by the designer for designer-database sync.) I'll try to get this fixed for you, but from my testing, you should be okay as long as you keep the naming strategy around. |
|
|
My naming strategy is setup in the config file and only maps the versioning column. I have turned on OCC in the entities I also noticed some other oddness... I added a couple more tables to the design surface and could the naming strategy have impacted on the new generated classes? Warning 15 'MindscapeTrial.ActivityRequestConsumerMobile.Version' hides inherited member 'MindscapeTrial.Activity.Version'. Use the new keyword if hiding was intended. C:\Projects\PocketVouchers\MindscapeTrial - Copy\MindscapeTrial\PocketVouchers.cs 824 16 MindscapeTrial Warning 16 'MindscapeTrial.ActivityRequestConsumerMobile.LockVersion' hides inherited member 'MindscapeTrial.Activity.LockVersion'. Use the new keyword if hiding was intended. C:\Projects\PocketVouchers\MindscapeTrial - Copy\MindscapeTrial\PocketVouchers.cs 892 16 MindscapeTrial Any thoughts about Bryn |
|
|
Regarding the manual LockVersion property not getting mapped to the Version column: I haven't been able to reproduce this problem -- it seems to be working correctly for me. Is it possible for you to your .lsmodel or (better) the generated .cs file, and your configuration file and naming strategy so I can investigate this problem? Thanks! (You can attach a zip file via the Options tab.) Regarding the shadowing of the Version and LockVersion properties: Basically you want to have each property (and property-backed options like OCC) at only one level of the inheritance hierarchy. The right place depends which kind of inheritance you are using. You say you added new tables so I am guessing this is either concrete table inheritance or class table inheritance. If it's concrete table inheritance then you would normally switch on Optimistic Concurrency Checking at the leaf level (not a base level). (We have a known bug with designer sync if you turn it on at a base level, though it will work fine for querying purposes.) Concrete table inheritance in LightSpeed isn't polymorphic so you don't normally have a base table in this scenario -- we really only expect leaf tables in this case. If it's class table inheritance then you would typically switch on OCC at the base level. However this will set the version only in the table corresponding to that level. If your existing schema defines a Version column at each level of the inheritance hierarchy, then I'm afraid you won't be able to use LightSpeed OCC -- we need to be able to map LockVersion to one column in one table, we can't cope with multiple Version columns in the different tables. |
|