I'm trying to map a type where one of the properties is an XmlDocument but I get this error:
NHibernate.MappingException : An association from the table ChangeLog_TestAuditHistory refers to an unmapped class: System.Xml.XmlDocument
I am using Fluent NHibernate automappings. NHibernate version 3.0.0.4000 and Fluent NHibernate version 1.2.0.694. I know NHibernate is supposed to support xml columns, but I've never seen any examples using auto mappings.
That's probably a bug in Fluent, or a wrong convention... you probably need to tell it that XmlDocument is not an entity.
If you map it as a regular property, NH will use the correct mapping by default.
Related
Using Fluent NHibernate, I have succeeded in setting up a global Filter on my NHibernate session, and using it in ClassMap classes. The Filter WHERE clause is appended to queries using that map automagically as it should - as described in other posts on this forum.
Fluent NHibernate does not implement ApplyFilter<> of SubclassMap, it is only implemented for ClassMap. It was easy to do a test by adding a filter through the back door, by passing a MappingProviderStore to the SubclassMap Constructor, and adding the filter to that. Inspecting the resulting classes in the debugger shows that everything is populated identically to a ClassMap. However, not surprisingly, this didn't work.
Can someone tell me if Filters SHOULD work with SubclassMap in NHibernate itself?
Is this therefore something that might eventually be supported (e.g. by implementing SubclassMap.ApplyFilter<>) in Fluent NHibernate?
Using Fluent NHibernate 2.1, with NHibernate 3.1
I'm supposing that fluent call apply filter the :
as per this Jira Entry, at Oct 2012 the function is not yet availavle in NH.
I'm working on a dynamic application with NHibernate. My goal is to create dynamic entities (both class type and mapping xml file) based on some data. For example suppose I want to create a Person entity dynamically in runtime and on the fly.
I use Reflection.Emit to generate class type dynamically. For creating mapping dynamically I used Ayende's code.. But unfortunately this code does not work because mappings does not have Classes property. I tried to code as same as codes of Castle ActiveRecord and Fluent NHibernate but they generate HBM XML files. As I don't want to generate/create mapping files so I can not use these solutions.
Is there any way that like Ayende's solution not to be forced to generate HBM XML mapping files and just doing everything dynamically and in memory?
fluentnhibernate creates hbm in memory just to feed them to nhibernate. fluentnhibernate has the nice automapping feature with costumizable conventions, perfect for this situation. Also in FNH 2.0 they are working to skip hbm for better performance, but normally you'll never see the mappings outside memory.
Sample:
Assembly assembly = GetDynamicallyCreatedTypesAssembly();
ISessionFactory sf = Fluently.Configure()
.Database(...)
.Mappings(m => m.AutoMappings.Add(AutoMap.Assembly(assembly)))
.BuildSessionFactory();
NHibernate 3.2 has a mapping-by-code layer that does what you want.
I'm not sure if dynamic classes will work, but it doesn't hurt to try.
Is there any way to get references to the mapping objects that NHibernate creates from the XML files? How about the ClassMap objects that FluentNhibernate creates? I wanted to create some query generation functions (for row counts, etc.) using this information. Since I went through the trouble of mapping it, I ought to have access to it in code, right?
Actually, Fluent ClassMaps are translated to XML.
The ISessionFactory exposes a GetAllClassMetadata method that is probably what you need.
Have a .net class that I want to persist/retrieve to/from Oracle 11g database using NHibernate. Contains an array of objects that NHibernate insists must be the interface type IDictionary, ISet, or IList. I also need to serialize the class to XML using XmlSerializer, however, XmlSerializer cannot serialize members of type IList (for example) "because it is an interface". Anyone have a solution to this problem?
NHibernate: How do I XmlSerialize an ISet<T>?
Bottom Line: Use DTOs.
I'm using Fluent NHibernate for my mappings and the SchemaExport class to the database schema.
Is it possible with NHibernate to set a default value for a property/column in the generated database schema?
Not to my knowledge, no - not in the generated schema.
You can just set the property in your constructor though.
It is definitely supported, both in XML mapping and in Fluent NHibernate.
For XML mapping, use the <column> child element of <property>, documented here.
For Fluent NHibernate, there's a method for fluent mapping, as described in this SO answer.