Formula will map to just one virtual-column.
You can't have different Formulas for the same column in the same hierarchy;
you can't apply polymorphism in the server-side because it does not know
what mean.

2010/9/26 Filip Kinský <[email protected]>

> Thanks for your advice.. Unfortunately denormalization of DisplayName is
> not viable solution in this case. I gave just simple sample classes, but
> there'll be more complex TransferParticipantBase-derived classes with
> DisplayName build from associated entities etc. Classes like:
>
> public abstract class CustomerTransferParticipant
> {
>    public Customer Customer { get; set; }
>    public override string DisplayName { get { return String.Format("{0}
> ({1})", Customer.Name, Customer.Number); }}
> }
>
> I don't want to denormalize DisplayName because of classes like this, where
> denormalization will force updating DisplayName every time related entity
> changes. I'm searching for some better solution which would handle
> DisplayName in polymorphic way... I thought the formula would let me do
> this, but the approach I tried to achieve is either not supported by NH or I
> just found some bug in NH3 Alpha.
>
>
> On Sat, Sep 25, 2010 at 4:52 AM, José F. Romaniello <
> [email protected]> wrote:
>
>> You can use access=“readonly“ in the property, this will persist the
>> value of the property and will let you to query...
>>
>> 2010/9/24, Filip Kinsky <[email protected]>:
>> > 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.
>> >
>> >
>>
>> --
>> Enviado desde mi dispositivo móvil
>>
>> --
>> 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]<nhusers%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/nhusers?hl=en.
>



-- 
Fabio Maulo

-- 
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.

Reply via email to