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, Consider the following object model which I'm trying to map to LightSpeed:
This however doesn't map well to a LightSpeed model due to inheritance. So I refactored it looks as follows:
For most part, I can map this with ease. Is it possible in LightSpeed to define the Original, Modified and Result properties of the DocumentComparison, without me having to write the query as I did? The following LINQ statement, which tries to find a list of "original documents" involved in comparisons, generates inefficient sql.
I'm looking to see if there is a way for LightSpeed to generate a single statement for the above query. The only work around I have is to create a method with a query that alomost looks the same as FindDocumentWIthRole in DocumentRelationship. I have about four different cases where the same pattern emerges, like relationships between parties (people and organizations). One thing to note is that I do this a bit:
And when we perform the comparison, I simply do the following:
This is the reason I use a property and do not return IQueryable. I'd be happy consider changing the model if that helps. Thanks, Werner |
|
|
Hmm, I'm not sure if I have fully grasped the structure or the query you're trying to run -- you describe it as 'find a list of "original" documents' but the code finds a list of comparisons in which a particular document acts as original. Assuming the code is correct, what you need to do is transform this into a query that relies only on mapped fields, not on helper methods (which cannot be translated to SQL and therefore force the query to run on the client). Here is my effort based on what I've understood of your model -- it could be wrong though...! Your original version:
Now we translate c.Original into mappable fields:
We can combine the Where with the Any:
But if c.Roles is an association then for any DocumentRole in c.Roles its Relationship must be c, because that's just the reverse association (I think):
Now we do have some restrictions on using traversals (r.RoleType.Name) with an Any so this may still not work. In that case, assuming the set of RoleTypes is reasonably static, you can cache the IDs of the role types (or even create an enum for them if they are fixed at the database level) and use the FK field:
Does that help or have I completely misunderstood how the associations go? |
|
|
Ivan, you understood the model perfectly. The role types are static. Writing the where clause is feasible. What I was really looking for is whether LightSpeed can do this: http://docs.jboss.org/hibernate/orm/3.3/reference/en/html/associations.html#assoc-complex Lets consider another (simpler) example:
Currently the model looks more like this:
This requires that I write helper methods to return the Primary name and OtherNames. What I'm was really wondering is whether I can tell LightSpeed that when Person.Name is referenced to ensure "IsPrimary = true" and in the case of Person.OtherNames, IsPrimary should be false. In a similar case if I wrote code like:
that the IsPrimary would be true when the new name is inserted. If I did something like this:
Then IsPrimary would be false. When I do a search, which is easy to understand:
Then somehow, LightSpeed will inject IsPrimary = true in the queries that searches for people with a family name of "Doe". I hope it makes sense. Thanks, Werner |
|
|
You might be able to do this using our LINQ property-expression mapping, though I'm not sure whether this would work with a traversal as in your |
|