流畅的nhibernate异常错误
我正在尝试在 MVC 项目中实现流畅的 nhibernate...没有构建错误...但是当我运行该项目时,我收到此异常,
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'.
不知道这里做错了什么...以下是打开会话工厂的代码...
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
这真的让我发疯...提前致谢...:)
更新映射 设计表映射
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
设计器表映射
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
新编辑 - 实体属性看起来像这样,
Public Overridable Property Name() As String
Get
Return _name
End Get
Protected Set(ByVal value As String)
_name = value
End Set
End Property
我走的路正确吗?
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..?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不太确定,因为映射看起来没问题。我可以看到一个错误,你只映射了一个类:
这不应该导致这种类型的错误。如果您添加这两个映射并调用方法
.ExportTo(@"C:\your\export\path")
您将获得实际的 xml 映射。这样就更容易看到错误。您可以这样做:如果您不想一一添加映射,您还可以使用 AddFromAssemblyOf 方法(或其他方法。有几种选择)。
尝试导出映射并查看是否发现任何错误。或者您可以发布 xml 映射,其他人可能会找到一些东西。
I'm not quite sure as the mappings seem ok. I can see one error tough, you have only mapped one of your classes:
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: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".
发现问题...地图的构造函数是错误的...应该是这样...
我猜是同时在 C# 和 vb.net 中工作的问题..!!
并且“Matthew Talbert”是正确的...使所有属性可重写很重要..
谢谢大家...:)
found the problem...the constructor for the map was wrong...it should be like this...
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...:)