c# - NHibernate "Could not determine type for X" error -
after upgrading nhibernate , fluentnhibernate dlls in project, i'm getting "could not determine type for: myapp.domain.entities.appcategory" exception thrown when initializing sessionfactory. change in code tweaking implementation of foreignkeyconvention override getkeyname ( member member, type type )
abstract method, instead of getkeyname ( propertyinfo property, type type )
.
the upgraded dlls 1.0.0.593 1.1.0.685 fluentnhibernate, , 2.1.0.4000 2.1.2.4000 nhibernate. part of difficulty in finding solution old age of nhibernate version we're using, can't changed, @ least now.
i posted full exception , relevant code , configuration below. apologize length, have no idea problem might be.
full exception
fluentnhibernate.cfg.fluentconfigurationexception : invalid or incomplete configuration used while creating sessionfactory. check potentialreasons collection, , innerexception more detail. ----> fluentnhibernate.cfg.fluentconfigurationexception : invalid or incomplete configuration used while creating sessionfactory. check potentialreasons collection, , innerexception more detail. ----> nhibernate.mappingexception : not compile mapping document: (xmldocument) ----> nhibernate.mappingexception : not determine type for: myapp.domain.entities.appcategory, myapp.domain, version=1.0.0.76, culture=neutral, publickeytoken=null, columns: nhibernate.mapping.column(appcategory) @ fluentnhibernate.cfg.fluentconfiguration.buildsessionfactory() in d:\builds\fluentnh\src\fluentnhibernate\cfg\fluentconfiguration.cs: line 98 @ myframework.app.dataaccess.nhibernate.databases.basedatabase.createsessionfactory() in c:\wip\vsprojects\myframework\src\app\dataaccess\nhibernate\databases\basedatabase.cs: line 115 @ myframework.app.dataaccess.nhibernate.databases.basedatabase.init() in c:\wip\vsprojects\myframework\src\app\dataaccess\nhibernate\databases\basedatabase.cs: line 100 @ myapp.dataaccess.smartstudiouserunitofwork.<.ctor>b__0() in smartstudiouserunitofwork.cs: line 28 @ myframework.app.dataaccess.nhibernate.unitofwork`1.create(flushmode flushmode) in c:\wip\vsprojects\myframework\src\app\dataaccess\nhibernate\unitofwork.cs: line 72 @ myframework.app.dataaccess.nhibernate.unitofwork`1..ctor(func`1 getbasedatabase) in c:\wip\vsprojects\myframework\src\app\dataaccess\nhibernate\unitofwork.cs: line 37 @ myapp.dataaccess.smartstudiouserunitofwork..ctor() in smartstudiouserunitofwork.cs: line 17 @ myapp.dataaccess.test.smartstudiouserdaotest.create_dao() in smartstudiouserdaotest.cs: line 20 --fluentconfigurationexception @ fluentnhibernate.cfg.fluentconfiguration.buildconfiguration() in d:\builds\fluentnh\src\fluentnhibernate\cfg\fluentconfiguration.cs: line 119 @ fluentnhibernate.cfg.fluentconfiguration.buildsessionfactory() in d:\builds\fluentnh\src\fluentnhibernate\cfg\fluentconfiguration.cs: line 93 --mappingexception @ nhibernate.cfg.configuration.logandthrow(exception exception) @ nhibernate.cfg.configuration.addvalidateddocument(namedxmldocument doc) @ nhibernate.cfg.configuration.processmappingsqueue() @ nhibernate.cfg.configuration.adddocumentthroughqueue(namedxmldocument document) @ nhibernate.cfg.configuration.addxmlreader(xmlreader hbmreader, string name) @ nhibernate.cfg.configuration.addinputstream(stream xmlinputstream, string name) @ nhibernate.cfg.configuration.adddocument(xmldocument doc, string name) @ nhibernate.cfg.configuration.adddocument(xmldocument doc) @ fluentnhibernate.persistencemodel.configure(configuration cfg) in d:\builds\fluentnh\src\fluentnhibernate\persistencemodel.cs: line 262 @ fluentnhibernate.automapping.autopersistencemodel.configure(configuration configuration) in d:\builds\fluentnh\src\fluentnhibernate\automapping\autopersistencemodel.cs: line 170 @ fluentnhibernate.cfg.automappingscontainer.apply(configuration cfg) in d:\builds\fluentnh\src\fluentnhibernate\cfg\automappingscontainer.cs: line 84 @ fluentnhibernate.cfg.mappingconfiguration.apply(configuration cfg) in d:\builds\fluentnh\src\fluentnhibernate\cfg\mappingconfiguration.cs: line 56 @ fluentnhibernate.cfg.fluentconfiguration.buildconfiguration() in d:\builds\fluentnh\src\fluentnhibernate\cfg\fluentconfiguration.cs: line 110 --mappingexception @ nhibernate.mapping.simplevalue.get_type() @ nhibernate.cfg.xmlhbmbinding.classbinder.bindproperty(xmlnode node, property property, idictionary`2 inheritedmetas) @ nhibernate.cfg.xmlhbmbinding.classbinder.createproperty(ivalue value, string propertyname, string classname, xmlnode subnode, idictionary`2 inheritedmetas) @ nhibernate.cfg.xmlhbmbinding.classbinder.bindjoin(xmlnode node, join join, idictionary`2 inheritedmetas) @ nhibernate.cfg.xmlhbmbinding.classbinder.propertiesfromxml(xmlnode node, persistentclass model, idictionary`2 inheritedmetas, uniquekey uniquekey, boolean mutable, boolean nullable, boolean naturalid) @ nhibernate.cfg.xmlhbmbinding.rootclassbinder.bind(xmlnode node, hbmclass classschema, idictionary`2 inheritedmetas) @ nhibernate.cfg.xmlhbmbinding.mappingrootbinder.addrootclasses(xmlnode parentnode, idictionary`2 inheritedmetas) @ nhibernate.cfg.xmlhbmbinding.mappingrootbinder.bind(xmlnode node) @ nhibernate.cfg.configuration.addvalidateddocument(namedxmldocument doc)
fluent configuration
sessionfactory = fluentconfiguration .mappings(m => m.automappings.add( automap.assemblyof<application>().conventions .add<customforeignkeyconvention>())) .exposeconfiguration(new schemaexport(config).create(true, false)) .buildsessionfactory(); public class customforeignkeyconvention : foreignkeyconvention { protected override string getkeyname ( member member, type type ) { if (member == null) { return type.name + "id"; } return member.name + "id"; } }
domain classes
public class application { public virtual int id { get; set; } public virtual string friendlyname { get; set; } public virtual appcategory appcategory { get; set; } } public class appcategory { public virtual int id { get; private set; } public virtual string categoryname { get; set; } }
database table definitions
create table [dbo].[application]( [id] [int] identity(1,1) not null, [friendlyname] [varchar](255) not null, [appcategoryid] [int] not null, constraint [pk_application] primary key clustered ([id] asc) ) go alter table [dbo].[application] check add constraint [fk_application_appcategory] foreign key([appcategoryid]) references [dbo].[appcategory] ([id]) go alter table [dbo].[application] check constraint [fk_application_appcategory] go create table [dbo].[appcategory]( [id] [int] identity(1,1) not null, [categoryname] [nvarchar](50) not null, constraint [pk_appcategory] primary key clustered ([id] asc) )
fluent nhibernate mapping
public class applicationmappingoverride : iautomappingoverride<application> { public void override(automapping<application> mapping) { mapping.table("application"); mapping.id(x => x.id); mapping.map(x => x.friendlyname); mapping.join("appcategory", x => x.map(y => y.appcategory)); } }
mapping xml (pulled fluent nhibernate log message):
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-access="property" auto-import="true" default-cascade="none" default-lazy="true"> <class xmlns="urn:nhibernate-mapping-2.2" mutable="true" name="myapp.domain.entities.application, myapp.domain, version=1.0.0.76, culture=neutral, publickeytoken=null" table="application"> <id name="id" type="system.int32, mscorlib, version=2.0.0.0, culture=neutral, publickeytoken=b77a5c561934e089"> <column name="id" /> <generator class="identity" /> </id> <property name="friendlyname" type="system.string, mscorlib, version=2.0.0.0, culture=neutral, publickeytoken=b77a5c561934e089"> <column name="friendlyname" /> </property> <join table="appcategory"> <key> <column name="applicationid" /> </key> <property name="appcategory" type="myapp.domain.entities.appcategory, myapp.domain, version=1.0.0.76, culture=neutral, publickeytoken=null"> <column name="appcategory" /> </property> </join> </class> </hibernate-mapping>
maybe late, still interested in solution i've found. i've faced same problem when trying override mappings 1 of entities.
the typical reason error when trying call map()
complex type. in case fluent nhibernate trying figure out type of entity map corresponding database type (e.g. int
integer
, bool
bit
, etc) , far there no such correspondence appcategory
type fails.
so error fixed if you'll change following line
mapping.join("appcategory", x => x.map(y => y.appcategory));
to one
mapping.join("appcategory", x => x.references(y => y.appcategory));
Comments
Post a Comment