Re: Mapping rewrite
"Fabio Maulo" <[email protected]>
| Newsgroups | gmane.comp.windows.dotnet.nhibernate.devel |
|---|---|
| Message-ID | <[email protected]> |
Ok. Do you can't use the SecondPassCommand delegate ? Mappings.AddSecondPass(SecondPassCommand) Mappings.AddSecondPass(SecondPassCommand, bool) 2008/6/29 Ayende Rahien <[email protected]>: > Sure. Sorry for that, I sometimes assume that everyone else knows whatever > I know. > > This is related to partial domain models. > > http://www.ayende.com/Blog/archive/2008/01/12/Creating-Partial-Domain-Models.aspx > > Imagine this entity: > > public class Permission > { > public Guid Id { get; set; } > public string Name { get; set; } > public IUser User { get; set; } > } > > public class UsersGroup > { > public Guid Id { get; set; } > public string Name { get; set; } > public ISet<User> Users { get; set; } > } > > Now, what I want to do is to be able to decide, at configuration time, what > is the concrete type that will be mapped to Permission.User. > The idea is to allow packaging this as a compiled DLL and then allow > different models to plug into this. > I can do this manually easily enough, by setting the class="" attrib on the > relevant mapping, but I want to be able to do this automatically and > programatically. > > Here is a simple example of what I want: > > cfg = new Configuration().AddAssembly("MyDomain").AddAssemly("Security"); > > RewriteReferences.From<IUser>().To<MyUser>(); > > cfg.BuildSessionFactory(); > > This will allow me to perform this modification without having to modify > the mapping files. > I could touch the NH mapping API directly. > > > On Sun, Jun 29, 2008 at 5:45 PM, Fabio Maulo <[email protected]> wrote: > >> Oren, do you can explain the situation ? (the problem to solve... the >> analysis... something in English...) >> I can't understand where put a code-chunk if I don't understand the >> target... >> >> Do you are trying to solve a generic association ? >> Do you have an interface in the mapping but you want strongly-type it >> before build-session-factory ? >> >> If this is the issue, would be better to end the study around >> "mapping-source". >> >> BTW without an whole picture I have some problem to understand what you >> need. >> >> >> 2008/6/29 Ayende Rahien <[email protected]>: >> >>> Runtime in this context means _before_ we call BuildSessionFactory, but >>> without touching the source XML files. >>> Ideally, I want to be able to run this at some point at the config build >>> lifetime: >>> >>> PersistentClass classMapping = cfg.GetClassMapping(userType); >>> foreach (PersistentClass persistentClass in cfg.ClassMappings) >>> { >>> //ignore non Rhino Security entities >>> if (persistentClass.MappedClass.Assembly != typeof(IUser).Assembly) >>> continue; >>> >>> foreach (Property property in persistentClass.PropertyIterator) >>> { >>> ManyToOne manyToOne = property.Value as ManyToOne; >>> if (manyToOne == null || manyToOne.ReferencedEntityName != >>> typeof(IUser).FullName) >>> continue; >>> ManyToOne value = new ManyToOne(classMapping.Table); >>> value.ReferencedEntityName = userType.FullName; >>> foreach (ISelectable selectable in manyToOne.ColumnIterator) >>> { >>> Column col = selectable as Column; >>> if (col != null) >>> { >>> value.AddColumn(col); >>> } >>> } >>> property.Value = value; >>> >>> Collection collection = property.Value as Collection; >>> if (collection == null || collection.IsOneToMany || >>> collection.GenericArguments.Length != 1 || >>> collection.GenericArguments[0] != typeof(IUser)) >>> continue; >>> IValue element = collection.Element; >>> } >>> >>> foreach (ForeignKey key in persistentClass.Table.ForeignKeyIterator) >>> { >>> if (key.ReferencedEntityName != typeof(IUser).FullName) >>> continue; >>> >>> key.ReferencedEntityName = userType.FullName; >>> key.ReferencedTable = classMapping.Table; >>> } >>> } >>> >>> On Sun, Jun 29, 2008 at 5:09 PM, Fabio Maulo <[email protected]> >>> wrote: >>> >>>> 2008/6/29 Ayende Rahien <[email protected]>: >>>> >>>>> I am _not_ interested in changing the XML. I am interested in >>>>> selecting, at runtime, what is the class of the many-to-many association. >>>>> There is a difference between them >>>>> >>>>> >>>> At run-time ok; but when ? >>>> You know, NH do the hard work of mapping at build-session-factory-time. >>>> So far only using <any> you can have an association really resolved at >>>> run-time. >>>> >>>> I need to understand what you are looking for to study the situation. >>>> -- >>>> Fabio Maulo >>>> >>>> ------------------------------------------------------------------------- >>>> Check out the new SourceForge.net Marketplace. >>>> It's the best place to buy or sell services for >>>> just about anything Open Source. >>>> http://sourceforge.net/services/buy/index.php >>>> _______________________________________________ >>>> Nhibernate-development mailing list >>>> [email protected] >>>> https://lists.sourceforge.net/lists/listinfo/nhibernate-development >>>> >>>> >>> >>> ------------------------------------------------------------------------- >>> Check out the new SourceForge.net Marketplace. >>> It's the best place to buy or sell services for >>> just about anything Open Source. >>> http://sourceforge.net/services/buy/index.php >>> _______________________________________________ >>> Nhibernate-development mailing list >>> [email protected] >>> https://lists.sourceforge.net/lists/listinfo/nhibernate-development >>> >>> >> >> >> -- >> Fabio Maulo >> ------------------------------------------------------------------------- >> Check out the new SourceForge.net Marketplace. >> It's the best place to buy or sell services for >> just about anything Open Source. >> http://sourceforge.net/services/buy/index.php >> _______________________________________________ >> Nhibernate-development mailing list >> [email protected] >> https://lists.sourceforge.net/lists/listinfo/nhibernate-development >> >> > > ------------------------------------------------------------------------- > Check out the new SourceForge.net Marketplace. > It's the best place to buy or sell services for > just about anything Open Source. > http://sourceforge.net/services/buy/index.php > _______________________________________________ > Nhibernate-development mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/nhibernate-development > > -- Fabio Maulo ------------------------------------------------------------------------- Check out the new SourceForge.net Marketplace. It's the best place to buy or sell services for just about anything Open Source. http://sourceforge.net/services/buy/index.php _______________________________________________ Nhibernate-development mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/nhibernate-development