I use NH 3.2 and Mapping by code in my project.
Today I try to set explicit polymorphism to some entities, but can't find how?
I know how to set it in .hbm or FNH, but not in Mapping by code!
Anybody can help me out?
I believe you are correct; explicit polymorphism setting from mapping-by-code has not been implemented yet.
If this is important to you, open a jira issue at http://nhibernate.jira.com
Nhibernate documentation specfies ReferenceAny() as a method to do the mapping inheritance trees.
Check doc here. However the code specifies the method as deprecated and will be removed in the next versions. Is there any other way to map this.
Only the ReferencesAny<TOther>(Member property) overload has been deprecated. ReferencesAny<TOther>(Expression<Func<T,TOther>> memberExpression) is still perfectly valid.
It's the same type of confusion as when people claim that Enum.ToString has been deprecated. The overloads that take an IFormatProvider have been deprecated, but the other ToString overloads are fine. The problem is that Intellisense shows the member stricken-out, even though only a subset of its overloads are actually obsolete.
For more information on using ReferencesAny in Fluent NHibernate, see my other answer: Mapping to multiple tables with Fluent nHibernate
I want to (auto)map a base class and its derived class to two different tables, as described here by ayende (unioned subclasses).
however, according to fluent nHibernate's documentation, I don't see a way do do that.
the property in IAutoMappingOverride they refer to is "IsDiscriminated", but that only difrrentiates between table-per-heirarchy and table-per-subclass.
Is it possible that automapping doesn't support unioned subclasses? and if so- can anyone suggest a workaround?
thanks,
Jhonny
I'm looking for more information on the extension points within NHibernate.
For instance I know about IUserType and ICacheProvider. However I can't seem to find a good reference of all the different extension points that NHibernate provides?
Is anyone's Google-fu stronger than mine :)
There are no complete references on that... but it's not hard to look at the assembly and find the interfaces and base classes:
IInterceptor
IBatcherFactory
ICollectionTypeFactory
IProxyFactoryFactory
ICacheProvider
IConnectionProvider
ICurrentSessionContext
Dialect
IDriver
IIdentifierGenerator
ITuplizer
And many more...
Take a look at *EventListener (newer mechanism) and IInterceptor (older mechanism, but useful in certain scenarios that EventListeners don't cover). They will get you a long way WRT extending/integrating with NHibernate.
http://www.nhforge.org/doc/nh/en/index.html#events
I have some entity types that I would like to lazy load. However, they have some internal (assembly) fields they expose, but are not used outside that class. These fields are compiler generated (F#) and I cannot change them. The an example exception is:
NHibernate.InvalidProxyTypeException:
The following types may not be used as
proxies: Mappings.MTest: field id#47
should not be public nor internal
I understand why NHibernate is doing this, and how having fields, if I accessed them, would mess up the lazy-loading properties of the proxies that are generated. However, since I know I won't be using the fields, can I override NHibernate somehow?
Is there any way I can say "ignore this field"? I'm using Fluent NHibernate, if that makes it easier.
Edit: I should also note, I'm using NHibernate 2.1.0 Alpha 2.
Edit2: The main gist here is that I want to keep LazyLoading enabled, which means I have to use the proxy generation. Disabling LazyLoading works (no proxies), but sorta defeats the purpose of a nice framework like NHibernate.
I reassembled NHibernate (easier than getting the source and rebuilding) and removed the code that errors on internal/public fields. LazyLoading appears to work just fine without that check. (Although, I'm new to NHibernate and so there are probably scenarios I don't know about.)
Edit:
Ah, there is a property, "use_proxy_validator" that will disable all validation checks. Good enough.
Fluently.Configure()
.ExposeConfiguration(fun cfg ->
cfg.Properties.Add("use_proxy_validator", "false"))...
Just set the lazy property to false,
<class name="OrderLine" table="OrderLine" lazy="false" >
you can read more in:
Must Everything Be Virtual With NHibernate? - http://davybrion.com/blog/2009/03/must-everything-be-virtual-with-nhibernate/
Ofir,
www.TikalK.com
You can use the
[XmlIgnore]
attribute to decorate the fields :)
Can you use an Interface to declare the fields "used" ?http://nhibernate.info/doc/nh/en/index.html#persistent-classes-poco-sealed
"Another possibility is for the class to implement an interface that declares all public members"
I don't know if NH use the same #transient annotation/attribute as the JAVA version to ignore a property in persistent operations.
You might want to take a look at this page which gives an overview of using F# with Fluent NHibernate.
Edit I just noticed your username. Am I correct in perhaps thinking that this is your blog? How foolish of me. It does seem to address your problem though, specifically "We start off by disabling LazyLoad because most of the properties are not virtual, and NHibernate will fail to validate the mapping. Instead, we explicitly LazyLoad things, like the Store reference."? Maybe I'm just misunderstanding the problem.