You can denormalize DisplayName as a calculated property:
Map(x => x.DisplayName).Access.ReadOnly()
You might have to map that in the base entity for it to work.
Diego
On Fri, Sep 24, 2010 at 05:58, Filip Kinsky <[email protected]> wrote:
> I have following domain model:
>
> public abstract class TransferParticipantBase: Entity
> {
> public abstract string DisplayName { get; }
> }
>
> public class Driver : TransferParticipantBase
> {
> ....
> public override string DisplayName
> {
> get { return LastName + " " + FirstName; }
> }
> }
>
> public class Store : TransferParticipantBase
> {
> ....
> public override string DisplayName
> {
> get { return Name; }
> }
> }
>
> So the DisplayName property is read-only and each subclass builds the
> value using different persistent properties. I'd like to add support
> for queries over DisplayName property, but I'm not able to fugure out
> how to define the mapping. The query should look like
> session.QueryOver<TransferParticipantBase>.Where(p => p.DisplayName =
> "test"). I tried following mapping (using FluentNH):
>
>
> public class TransferParticipantMap:
> ClassMap<TransferParticipantBase>
> {
> public TransferParticipantMap()
> {
> Id(x => x.Id);
> }
> }
>
> public class DriverMap: SubclassMap<Driver>
> {
> public DriverMap()
> {
> Map(x => x.DisplayName)
> .Access.None()
> .Formula("LASTNAME || ' ' || FIRSTNAME");
> Map(x => x.FirstName);
> Map(x => x.LastName).Not.Nullable();
> }
> }
>
> public class StoreMap: SubclassMap<Store>
> {
> public StoreMap()
> {
> Table("STORE");
> Map(x => x.DisplayName)
> .Access.None()
> .Formula("NAME");
> Map(x => x.Name).Not.Nullable();
> }
> }
>
>
> This unfortunately does not work - NH generates wrong SQL. I get SQL
> like "...WHERE DRIVER.NAME LIKE @p0" instead of something like
> "...WHERE STORE.NAME LIKE @p0 OR (DRIVER.LASTNAME || ' ' ||
> DRIVER.FIRSTNAME) LIKE @p0". It looks like DisplayName mapping with
> formula for Store applies to both entities.
>
> Is there any chance I could get this working without redesigning my
> entities? I'm using NH 3 Alpha.
>
> --
> You received this message because you are subscribed to the Google Groups
> "nhusers" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<nhusers%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/nhusers?hl=en.
>
>
--
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/nhusers?hl=en.