gpt4 book ai didi

c# - 命名空间 'class' 中的元素 'urn:nhibernate-mapping-2.2' 具有无效的子元素 'property'

转载 作者:太空狗 更新时间:2023-10-29 21:06:08 24 4
gpt4 key购买 nike

hbm 文件是:

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="EMSApplication.Domain.Employee, EMSApplication.Domain" table="ems_Employees" proxy="EMSApplication.Domain.IEmployee, EMSApplication.Domain">
<property name="Username">
<column name="Username" length="40" sql-type="nvarchar" not-null="true" index="Username"/>
</property>
<property name="Firstname">
<column name="Firstname" length="40" sql-type="nvarchar" not-null="true" index="Firstname"/>
</property>
</class>
</hibernate-mapping>

Employee.cs:

namespace EMSApplication.Domain {
public class Employee : IEmployee {
private string username;
private string firstname;

public virtual string Firstname {
get {
return firstname;
}
set {
firstname = value;
}
}

public virtual string Username {
get {
return username;
}
set {
username = value;
}
}
}
}

这是 IEmployee.cs:

namespace EMSApplication.Domain {
interface IEmployee {
string Firstname { get; set; }
string Username { get; set; }
}
}

现在我得到了异常:

The element 'class' in namespace 'urn:nhibernate-mapping-2.2' has invalid child element 'property' in namespace 'urn:nhibernate-mapping-2.2'. List of possible elements expected: 'meta, subselect, cache, synchronize, comment, tuplizer, id, composite-id' in namespace 'urn:nhibernate-mapping-2.2'.

我正在使用带有 NHibernate 的 Spring.Net。 hbm文件的调用是:

<object id="NHibernateSessionFactory" type="Spring.Data.NHibernate.LocalSessionFactoryObject, Spring.Data.NHibernate32">
<property name="DbProvider" ref="DbProvider"/>
<property name="MappingResources">
<list>
<value>assembly://EMSApplication/EMSApplication.Domain/EMSApplication.hbm.xml</value>
</list>
</property>
<property name="HibernateProperties">
<dictionary>
<entry key="hibernate.connection.provider" value="NHibernate.Connection.DriverConnectionProvider"/>
<entry key="dialect" value="NHibernate.Dialect.MsSql2008Dialect"/>
<entry key="connection.driver_class" value="NHibernate.Driver.SqlClientDriver"/>
<entry key="proxyfactory.factory_class" value="NHibernate.Bytecode.DefaultProxyFactoryFactory, NHibernate"/>
<entry key="show_sql" value="true"/>
<entry key="hbm2ddl.auto" value="update"/>
<entry key="cache.use_query_cache" value="true"/>
</dictionary>
</property>

<property name="ExposeTransactionAwareSessionFactory" value="true" />
</object>

项目结构是:

enter image description here

任何帮助都会很有帮助。

谢谢。

最佳答案

您缺少 id 元素,它位于架构中所有属性之前。

关于c# - 命名空间 'class' 中的元素 'urn:nhibernate-mapping-2.2' 具有无效的子元素 'property',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9775934/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com