简体   繁体   English

流利的NHibernate异常错误

[英]fluent nhibernate Exception error

am trying to implement fluent nhibernate in MVC project...there were no build errors... but when i run the project i get this exception 我正在尝试在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'.

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. 如果同时添加两个映射并调用方法.ExportTo(@"C:\\your\\export\\path") ,则将获取实际的xml映射。 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. 如果您不想一个接一个地添加映射,也可以使用方法AddFromAssemblyOf (或其他方法。有几种选择)。

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. 或者,您可以发布xml映射,其他人可能会发现一些东西。

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..!! 我想同时在C#和vb.net中工作的问题.. !!

and "Matthew Talbert" was correct...making all the properties Overrideable is important.. 而“马修·塔伯特(Matthew Talbert)”是正确的……使所有属性“可重写”很重要。

thanks guys...:) 多谢你们...:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM