When presented with a 1:1 relationship like this i almost always end
up changing my mapping from a "Is-a" to a "part-of" relationship
public class Animal { }
public class Dog {
public Animal {get;set}
}
Oskar is right, you cannot just change a object's type in this way, .
On Mar 21, 3:43 am, Oskar Berggren <[email protected]> wrote:
> Well you can't, can you? :)
>
> NHibernate stores object. Just as you can't suddenly change the type
> of an object in memory, you cannot do so with NHibernate. Of course,
> since there is a relational DB below, you can go ahead with ordinary
> SQL to tweak the database so NHibernate considers it a Dog when loaded
> again. Usually this is a bad idea though, and you should think of a
> way to achieve your real goal without trying to make objects change
> type.
>
> /Oskar
>
> 2011/3/21 KotuadaM <[email protected]>:
>
>
>
>
>
>
>
> > Yes, thats the exact question.
>
> > On Mon, Mar 21, 2011 at 10:24 AM, Oskar Berggren <[email protected]>
> > wrote:
>
> >> If you have an instance of Animal in memory, how would you convert it
> >> to an instance of Dog?
>
> >> /Oskar
>
> >> 2011/3/21 KotuadaM <[email protected]>:
> >> > Ho to cast an object in DB to its inherited type?
> >> > Lets say I have 2 classes.
> >> > public class Animal { }
> >> > public class Dog : Animal { }
> >> > Step 1:
> >> > Create an instance of Animal and save it into the DB in NHibernate.
> >> > Step 2:
> >> > Call the created instance of Animal and take its ID and insert a new
> >> > instance of Dog in the database with the ID of Animal instance. So now
> >> > the
> >> > previously inserted Animal will now be Dog in the database.
>
> >> > Any idea how to do this?
>
> >> > --
> >> > 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.
>
> >> --
> >> 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.
>
> > --
> > 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.
--
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.