gpt4 book ai didi

c# - 似乎无法使 nhibernate 与 mysql 一起工作

转载 作者:行者123 更新时间:2023-11-29 12:31:12 25 4
gpt4 key购买 nike

我在设置 NHibernate 来使用 mysql 数据库时遇到问题......错误:

[InvalidProgramException: JIT Compiler encountered an internal limitation.] NHibernate.Cfg.MappingSchema.HbmId.get_Type() +0 NHibernate.Cfg.XmlHbmBinding.ClassIdBinder.BindId(HbmId idSchema, PersistentClass rootClass, Table table) +477 NHibernate.Cfg.XmlHbmBinding.RootClassBinder.Bind(HbmClass classSchema, IDictionary2 inheritedMetas) +1901
NHibernate.Cfg.XmlHbmBinding.MappingRootBinder.AddRootClasses(HbmClass rootClass, IDictionary
2 inheritedMetas) +295 NHibernate.Cfg.XmlHbmBinding.MappingRootBinder.AddEntitiesMappings(HbmMapping mappingSchema, IDictionary`2 inheritedMetas) +321 NHibernate.Cfg.XmlHbmBinding.MappingRootBinder.Bind(HbmMapping mappingSchema) +316 NHibernate.Cfg.Configuration.AddDeserializedMapping(HbmMapping mappingDocument, String documentFileName) +489

[MappingException: Could not compile the mapping document: WebGest.NET.DomainModel.Mappings.XML.Operator.hbm.xml] NHibernate.Cfg.Configuration.LogAndThrow(Exception exception) +220 NHibernate.Cfg.Configuration.AddDeserializedMapping(HbmMapping mappingDocument, String documentFileName) +741 NHibernate.Cfg.Configuration.AddValidatedDocument(NamedXmlDocument doc) +233 NHibernate.Cfg.Configuration.ProcessMappingsQueue() +121 NHibernate.Cfg.Configuration.AddDocumentThroughQueue(NamedXmlDocument document) +195 NHibernate.Cfg.Configuration.AddXmlReader(XmlReader hbmReader, String name) +217 NHibernate.Cfg.Configuration.AddInputStream(Stream xmlInputStream, String name) +284 NHibernate.Cfg.Configuration.AddResource(String path, Assembly assembly) +483 NHibernate.Cfg.Configuration.AddAssembly(Assembly assembly) +459 NHibernate.Cfg.Configuration.AddAssembly(String assemblyName) +410 NHibernate.Cfg.Configuration.DoConfigure(ISessionFactoryConfiguration factoryConfiguration) +1935 NHibernate.Cfg.Configuration.Configure() +269 WebGest.NET.DomainModel.NHSessionFactory.Init() in e:\dev\C#\WebGest.net\webgest\WebGest.NET\DomainModel\NHSessionFactory.cs:21 WebGest.NET.DomainModel.NHSessionFactory.GetSessionFactory() in e:\dev\C#\WebGest.net\webgest\WebGest.NET\DomainModel\NHSessionFactory.cs:32 WebGest.NET.DomainModel.NHSessionFactory.get_Instance() in e:\dev\C#\WebGest.net\webgest\WebGest.NET\DomainModel\NHSessionFactory.cs:45 WebGest.NET.DomainModel.NHSession..cctor() in e:\dev\C#\WebGest.net\webgest\WebGest.NET\DomainModel\NHSession.cs:12

[TypeInitializationException: The type initializer for 'WebGest.NET.DomainModel.NHSession' threw an exception.] WebGest.NET.Login.Page_Load(Object sender, EventArgs e) in e:\dev\C#\WebGest.net\webgest\WebGest.NET\WebGest.NET\Login.aspx.cs:16 System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +188 System.EventHandler.Invoke(Object sender, EventArgs e) +0 System.Web.UI.Control.OnLoad(EventArgs e) +162 System.Web.UI.Control.LoadRecursive() +164 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3601

Web.config:

 <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<reflection-optimizer use="false" />
<session-factory>
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="connection.driver_class">NHibernate.Driver.MySqlDataDriver</property>
<property name="connection.connection_string">Server=localhost;Database=webgest;User ID=root;Password=;</property>
<property name="dialect">NHibernate.Dialect.MySQL5Dialect</property>
<mapping assembly="DomainModel" />
</session-factory>
</hibernate-configuration>

映射文件:

   <?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
namespace="WebGest.NET.DomainModel"
assembly="DomainModel">
<class name="Operator" table="s_operatori">

<id name="IdOperator" column="IdOperator" unsaved-value="0">
<generator class="native" />
</id>

<property name="User">
<column name="User" not-null="true" />
</property>

<property name="Parola">
<column name="Parola" not-null="false" />
</property>

<property name="FlagActiv">
<column name="FlagActiv" not-null="true" />
</property>
</class>
</hibernate-mapping>

CS:

   namespace WebGest.NET.DomainModel
{
public partial class Operator
{
public virtual int IdOperator { get; set; }
public virtual string User { get; set; }
public virtual string Parola { get; set; }
public virtual bool FlagActiv { get; set; }
public Operator() { }
}
}

那我做错了什么?

此外,asp.net 站点与包含 NHibernate 和 mysql 引用的“domainmodel”项目位于一个单独的项目中,这两个项目位于同一解决方案中。

最佳答案

尝试揭示异常的内部异常:

{"Could not compile the mapping document: WebGest.NET.DomainModel.Mappings.XML.Operator.hbm.xml"}

将会有明确的信息、明确的消息。例如:

{"persistent class WebGest.NET.DomainModel.Operator, DomainModel not found"}

这意味着具有 Operator 类的项目未加载。如果 Operator 未在 DomainModel 程序集中定义,情况就是如此……

但我在这里猜测.. 内部异常会清楚地告诉你...

关于c# - 似乎无法使 nhibernate 与 mysql 一起工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27472376/

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