Replies: 1 comment
-
Also, I should state the problem.. With the mappings above, we then need to query a GenericSubEntity by its parent. session.Query<GenericSubEntity>().Where(c => c.Parent.Id == '17UDLonYb020dNnlxt');
//We've also tried,
session.Query<GenericSubEntity>().Where(c => c.Parent.Id.Equals('17UDLonYb020dNnlxt'));
//and
session.Query<GenericSubEntity>().Where(c => c.Parent == new BaseEntity('17UDLonYb020dNnlxt'));
// there is a proper Equals implementation on BaseEntity When that query runs, the following SQL is generated. Note the where clause does not include the ParentId column. It is not mapped correctly from the Linq expression. // sql generated by NH - genericsub0_.Id is the wrong column
select genericsub0_.Id as id1_17_, genericsub0_.ChangeCount as changecount3_17_, genericsub0_.ParentId as parentid4_17_ from GenericSubEntity genericsub0_ where genericsub0_.Id='17UDLonYb020dNnlxt' Instead, is the where clause should be genericsub0_.ParentId = '17UDLonYb020dNnlxt' select genericsub0_.Id as id1_17_, genericsub0_.ChangeCount as changecount3_17_, genericsub0_.ParentId as parentid4_17_ from GenericSubEntity genericsub0_ where genericsub0_.ParentId='17UDLonYb020dNnlxt'
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
I've been using Nh and FluentNh for many years. We're using it for a project currently where the entire system is made of user defined dynamic associations and polymorphic sub typing. Consequently a domain layer is responsible for loading entities and collections. In order to achieve this no foreign keys exist in the database. We understand all the ways this breaks the model of many nhibernate association/composition functions/conventions.
Here are the persistent models.
here are the maps
This is the relevant portions of custom type we use to persist/retrieve the parent - in the domain layer the full entity is loaded if needed.
There are many subtypes of GenericEntity and the GenericSubEntity.Parent can reference any of them.
In other projects I have used ReferencesAny for a situation like this. I would like to do that here but I cannot change the schema. So what I'm looking to do is specify these same column for the EntityType and the EntityIdentifer. The reason is we use a single value, for example '17UDLonYb020dNnlxt' to store both the type information and the identifier. We do this so that this single value can be used as a reference anywhere in the rest of the system. Briefly the first 4 characters of the base 96 value represents a type id. There is common code available at runtime to resolve the typeid to a concrete persistent type. What we're looking to do is essentially extend ReferencesAny such that we can persist a single column, then when querying we can (with a custom class) map the id value to a persistent type and then do the equivalent of session.Load(type, id) dynamically for the parent.
I hope this makes sense to everyone. Thanks.
Beta Was this translation helpful? Give feedback.
All reactions