I'm pretty sure NHibernate doesn't allow you to do this. You can't change the *type* of an entity once it's been created. I'd review your design if this is an integral point. It sounds like you need a State property, not a subclass.
On Wed, Jul 29, 2009 at 8:06 AM, Maik Brunner <[email protected]>wrote: > > Hi, > > I am currently working on a project where I am using Fluent NHibernate > for the first time. I have a class named "Download" which has an > inherited child "ProcessedDownload". In my business logic the > downloads are processed and then should be stored as entity of type > "ProcessedDownload". Can someone give me a hint how to create an > "ProcessedDownload" entity based on a loaded "Download" entity and > then save this entity keeping the id of the original "Download" entity > and not creating a new entity with a new id? > > Thanks in advance. > > Code: > > public class DownloadMap : ClassMap<Download> > { > public DownloadMap() > { > Id(x => x.ID) > .GeneratedBy.Native(); > > Map(x => x.Name) > .Not.Nullable(); > Map(x => x.Size) > .Not.Nullable(); > Map(x => x.CreationTime) > .Not.Nullable(); > Map(x => x.ProcessedTime); > Map(x => x.Status) > .CustomTypeIs(typeof(DownloadStatusType)); > > References(x => x.Customer) > .WithForeignKey() > .LazyLoad() > .Not.Nullable() > .Cascade.All(); > > References(x => x.DownloadContent) > .WithForeignKey() > .LazyLoad() > .Not.Nullable() > .Cascade.All(); > > JoinedSubClass("Download_Id", > ProcessedDownloadMap.AsJoinedSubClass()); > } > } > > public class DownloadContentMap : ClassMap<DownloadContent> > { > public DownloadContentMap() > { > Id(x => x.ID) > .GeneratedBy.Native(); > > Map(x => x.Content) > .Access.AsCamelCaseField(Prefix.Underscore) > .Not.Nullable() > .CustomSqlTypeIs("varbinary(MAX)"); > } > } > > public class ProcessedDownloadMap > { > public static Action<JoinedSubClassPart<ProcessedDownload>> > AsJoinedSubClass() > { > return part => > { > part.Map(x => x.DownloadTime) > .Not.Nullable(); > part.Map(x => x.DownloadBeginTime); > part.Map(x => x.DownloadEndTime); > > part.References(x => x.Equipment) > .LazyLoad() > .Not.Nullable() > .Cascade.All(); > > part.References(x => x.Customer) > .LazyLoad() > .Not.Nullable() > .Cascade.All(); > }; > } > } > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Fluent NHibernate" 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/fluent-nhibernate?hl=en -~----------~----~----~----~------~----~------~--~---
