开发者

fluent nhibernate Exception error

开发者 https://www.devze.com 2022-12-18 16:18 出处:网络
am trying to implement fluent nhibernate in MVC project...there were no build errors... but when i run the project i get this exception

am trying to implement fluent nhibernate in MVC project...there were no build errors... but when i run the project i get this exception

System.Xml.Schema.XmlSchemaValidationException: The element 'class' in namespace 'urn:nhibernate-mapping-2.2' has incomplete content. List of possible elements expected: 'meta, subselect, cache, synchronize, comment, tuplizer, id, composite-id' in namespace 'urn:nhibernate-mapping-2.2'.

have no idea what am doing wrong here... the following is the code for opening session factory...

Private Function CreateSessionFactory() As ISessionFactory
    Dim sessionFactoryObject As ISessionFactory
    sessionFactoryObject = Fluently.Configure().Database(FluentNHibernate.Cfg.Db.MsSqlConfiguration.MsSql2005.ConnectionString("Data Source=.\sqlexpress;Initial Catalog=Designs;User ID=sa;Password=root")).Mappings(Function(x) x.FluentMappings.Add(GetType(DesignMap))).BuildSessionFactory()
    Return sessionFactoryObject
End Function

this is 开发者_开发百科really driving me nuts....thanks in advance...:)

update-the mappings the design table map

Public Class DesignMap
Inherits ClassMap(Of Design)

Public Sub DesignMap()
    Table("DesignList")
    Id(Function(x) x.DesignId)
    Map(Function(x) x.DesignType)
    References(Function(x) x.Designer, "DesignerId")
End Sub
End Class

the designer table map

Public Class DesignerMap
Inherits ClassMap(Of Designer)
Public Sub DesignerMap()
    Table("DesignerList")
    Id(Function(x) x.DesignerId)
    Map(Function(x) x.DesignerName)
    Map(Function(x) x.DesignerCompany)
    HasMany(Function(x) x.DesignersDesigns)
End Sub
End Class

new edit-- the entity property looks like this

    Public Overridable Property Name() As String
     Get
        Return _name
     End Get
     Protected Set(ByVal value As String)
        _name = value
     End Set
    End Property

am i going the right way..?


I'm not quite sure as the mappings seem ok. I can see one error tough, you have only mapped one of your classes:

.Mappings(Function(x) x.FluentMappings.Add(GetType(DesignMap)))

That should not cause this type of error tough. If you add both your mappings and call the method .ExportTo(@"C:\your\export\path") you will get the actual xml mappings. This way it's easier to see the error. You can do that like this:

.Mappings(Function(x) x.FluentMappings.Add(GetType(DesignMap)).Add(GetType(DesignerMap
).ExportTo(@"C:\your\export\path"))

You can also use the method AddFromAssemblyOf (or some other. There is a few choices) if you don't want to add the mappings one by one.

Try exporting the mappings and see if you can find any error. Or you can post the xml mappings and someone else might find something.


There are several things that can cause this. When using automappings, you will get this if you incorrectly specify the assemblies and namespaces to look in. Other things (more likely in your case) that could cause it, are entity properties that aren't marked as public virtual, having an entity constructor with arguments, but neglecting to make a default constructor, or inheriting your entities from a base class.

I would probably first check to make sure all of your entity properties are "public virtual".


found the problem...the constructor for the map was wrong...it should be like this...

Public Class DesignMap
 Inherits ClassMap(Of Design)

 Public Sub New()
  Table("DesignList")
  Id(Function(x) x.DesignId)
  Map(Function(x) x.DesignType)
  References(Function(x) x.Designer, "DesignerId")
End Sub
End Class

problems of working in both C# and vb.net at the same time i guess..!!

and "Matthew Talbert" was correct...making all the properties Overrideable is important..

thanks guys...:)

0

精彩评论

暂无评论...
验证码 换一张
取 消