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
|
Hello - From what I understand LightSpeed requires an ID field to be happy with its lot in life. Unfortunately that situation isn't always attainable. The Oracle database I am working with has at least one view (the one I have to work with) that has no intrinsic ID field. This view basically acts as a link table between the Bill Of Materials (BOM) header table and the detail records for the items in the BOM. Obviously, LightSpeed complains about this. Is there an elegant way to get around this? I'm not happy with any of the solutions I can think of. There is a column in the table that is probably unique, but there's certainly no guarantee of that, and I absolutely have no options of changing the database structure to accommodate your toolset. Oh yeah, I am using LightSpeed 4, nightly build from 6/20. VS2010 SP1. Thanks, Dave |
|
|
If it helps, here is the text of the exception and I have attached the model project... I had to edit the model.cs file, as it keeps trying to duplicate ARINVTID as the foreign key instead of using OPMATARINVTID as I tried to do via the designer. ARINVTID is the field I might be able to use as the ID field, but I really don't want to do that. There was an error processing the request
Oracle.DataAccess.Client.OracleException ORA-06550: line 526, column 15:
PLS-00302: component 'ID' must be declared
ORA-06550: line 526, column 3:
PL/SQL: ORA-00904: "VBOMOPMAT"."ID": invalid identifier
ORA-06550: line 525, column 1:
PL/SQL: SQL Statement ignored at Oracle.DataAccess.Client.OracleException.HandleErrorHelper(Int32 errCode, OracleConnection conn, IntPtr opsErrCtx, OpoSqlValCtx* pOpoSqlValCtx, Object src, String procedure, Boolean bCheck)
at Oracle.DataAccess.Client.OracleException.HandleError(Int32 errCode, OracleConnection conn, String procedure, IntPtr opsErrCtx, OpoSqlValCtx* pOpoSqlValCtx, Object src, Boolean bCheck)
at Oracle.DataAccess.Client.OracleCommand.ExecuteReader(Boolean requery, Boolean fillRequest, CommandBehavior behavior)
at Oracle.DataAccess.Client.OracleCommand.ExecuteDbDataReader(CommandBehavior behavior)
at System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader()
at . . . ()
at Mindscape.LightSpeed.Profiling.Interceptor.ExecuteCommand(Func |
|
|
You must have a unique primary key field or composite key fields which can be used to form the identity for the entity. This is a basic requirement of LightSpeed. If this is not possible then it wont be possible to map an entity against that table. If you need to map the Id field to a different column name you can set the Identity Column Name property on the entity. If you need to use a composite key then have a read through this section of the documentation: http://www.mindscapehq.com/documentation/lightspeed/Working-with-Legacy-Databases/Using-Composite-Keys
|
|
|
Still working through the intricacies of the Oracle database -- I haven't had a lot of luck getting the data I need out of there yet. After studying the problem from several angles, digging around on the web, and talking with our business expert (he didn't create the database but he's responsible for getting stuff out of it) I have concluded views rarely have defined indexes, let alone surrogate keys. That makes sense - after all a view is just a canned query, right? So the entity I need to map has no defined key. There are 2 fields that are used for that purpose, but they are not defined as such. How in the world do I use your product with such an entity? Surely this is not that unusual of a problem. I thought about duplicating the view logic in code but that would require pulling in 3 tables that have no other value than connecting the tables I need data from... Anyway - when I drag the view onto the design surface I get the graphic with all fields listed, but no associations and no identity. This means I need to define the composite key and associations in the model. I'm not entirely sure how to define the identity when LS can't do so, even after reading and re-reading the documentation. The docs seem to assume the identity got pulled in when the table was imported. Either that or the entity is completely hand-coded. The section on implementing GeneratedId is a little confusing when I try to apply it to your generated code. The section on Composite Keys in Hand-Coded Entities seems to be the most applicable but this is NOT a hand-coded entity. Please excuse my apparent ignorance, I'm trying to wrap my head around this but it still seems to be elusive. Any suggestions? Thanks in advance, Dave |
|
|
I would also like to know where the identity of a given entity is defined. Some time spent digging through the generated code and everything else I could find yields no luck for me. I can see it is specified as a type on the class declaration (public partial class VBomOpmat : Entity It would also be nice to have the option of displaying the hidden fields in the model, similar to the example in the composite key doc where it shows fields under the heading "Identity" and the rest of the fields under the heading "Properties". I know, "convention over configuration" and all that, but it really would be nice to have a visual confirmation of what I think is happening behind the curtain. How do I make that happen? Sorry for the confusion, I'm sure it's not all attributable to your product. From what I have seen, most Oracle database designers tend to be overly clever in their implementations... |
|
|
The entity has to have an identity field. If it is not possible to define one then you wont be able to define a LightSpeed entity to reflect the underlying table or view you want to work over. You could however look at using a projection for this type of situation . e.g. UnitOfWork.Project() but the resulting objects will not be managed by LightSpeed and you would use these a read-only fashion. This section in the documentation walks through what is involved code wise in specifying an entity definition which I believe should help give a bit more understanding about how the identity gets defined: http://www.mindscapehq.com/documentation/lightspeed/Creating-Domain-Models/Creating-Models-in-Code If you need to re-map the Id property to a column name other than Id you can set the Identity Column Name property for the entity in the designer.
|
|
|
Just as a follow-up, re-reading what you have said above it does sound like there is no clear identity property or composite key that can be created for the entity (entities?) you are trying to work with. If this is the case then as I mentioned above you will not be able to define an entity so definitely have a look at if using UnitOfWork.Project or UnitOfWork.FindBySql might be more appropriate in this case. If this only is a problem for a couple of tables in your database I imagine you can probably work around this however if this is the case for most or all of the tables you are looking at then LightSpeed is not going to be a runner in this instance.
|
|
|
Ugh. I was hoping for somewhat better options. Actually there is only one view I am concerned with, so it shouldn't be that big a deal to work around it. Better yet, I was just talking with our business expert Jeff and he informed me he can create a view identical to the existing view with a dummy surrogate ID field to satisfy LightSpeed's requirement for an identity field. He's not real happy with doing that as it means creating a custom database entity he has to keep track of separate from any vendor updates, but we both agreed it is a lot less work than hand-coding ORM logic. Anyway I'm glad I found a way around this but I would like to suggest that someone there create a sample project to cover this situation, where the database entity has no intrinsic ID field(s). Thanks for the response, Dave |
|