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 a view which joins 2 tables - an attribute value table and an attribute type table which I use to give me a single entity with fields/properties from both tables. This works well until I want to insert or update back to the DB in that there's a type description property (from the attribute type table) that should'nt be passed back in the Lightspeed insert/update. So essentially it's a text property for display only and can only be inserted/updated with an attributetypeID. If I set the transient property to true for this field then it won't be fetched from the DB in the entity select. I was hoping that there is a way to set this up as required. So the TSQL generated by Lightspeed is the following - exec sp_executesql N'INSERT INTO StockAttrib SELECT scope_identity()',N'@p0 int,@p1 nvarchar(7),@p2 int',@p0=278,@p1=N'foo.gif',@p2=21428
But it needs to be like this - exec sp_executesql N'INSERT INTO StockAttrib SELECT scope_identity()',N'@p0 int,@p1 nvarchar(7),@p2 int',@p0=278,@p1=N'foo.gif',@p2=21428 Cheers John
|
|
|
Just to clarify, you want a property that is fetched *from* the database during SELECTs, but not sent *to* the database during INSERTs or UPDATEs? If so, I'm afraid that's not supported. Our recommendation would be to model the second table (the type table) as a second kind of entity, and use eager loading to ensure that it loads efficiently. You could then refer to the type code as stockAttrib.Type.Code (and of course could create a wrapper property on StockAttrib to encapsulate this). |
|
|
Thanks for your reply Ivan and yes your understanding is correct. In this case we don't want our object domain to resemble our DB schema as this is a normalised data structure and not how we'd want our object to work. This is where Lightspeed support for views is great as we can abstract our object model away from the underlying schema. However when the view is from multiple tables, then the update/insert becomes an issue as in our case. One solution is to implement stored procedures with our object for insert and update but this also means creating select and select by id stored procs which we can do but we'd rather just have the simple select from the view. Cheers John
|
|
|
Hello John, It's amazing what you find in old release announcements! It turns out that if you set a field to readonly, then it will be loaded from the database (i.e. included in SELECTs), but will not be saved (not included in an INSERT or UPDATE). Note that the backing field must be marked readonly: private readonly int _age; Making the wrapper property get-only is NOT enough. Please note the designer does not support readonly fields so you would need to implement this in the partial class. Hope this helps and sorry for the delay in letting you know about this -- I only just found out myself! |
|