Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/rust/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Nhibernate 使用guid的Sharp架构_Nhibernate_Fluent Nhibernate_S#arp Architecture - Fatal编程技术网

Nhibernate 使用guid的Sharp架构

Nhibernate 使用guid的Sharp架构,nhibernate,fluent-nhibernate,s#arp-architecture,Nhibernate,Fluent Nhibernate,S#arp Architecture,我正在使用Sharp Architecture 1.6 VS2010并研究如何使用GUI 但我遇到了一个我无法解决的错误 个人实体 using System; using NHibernate.Validator.Constraints; using SharpArch.Core.DomainModel; namespace SharpDemo.Core { public class Person : EntityWithTypedId<Guid> { [

我正在使用Sharp Architecture 1.6 VS2010并研究如何使用GUI 但我遇到了一个我无法解决的错误

个人实体

using System;
using NHibernate.Validator.Constraints;
using SharpArch.Core.DomainModel;

namespace SharpDemo.Core
{
   public class Person : EntityWithTypedId<Guid>
   {
       [NotNullNotEmpty(Message = "First name must be provided.")]
       public virtual string FirstName { get; set; }

       [NotNullNotEmpty(Message = "Last name must be provided.")]
       public virtual string LastName { get; set; }
   }
}
堆栈跟踪

[FormatException: Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).]
   System.Guid..ctor(String g) +2486
   NHibernate.Type.GuidType.FromStringValue(String xml) +75
   NHibernate.Type.GuidType.StringToObject(String xml) +86
   NHibernate.Engine.UnsavedValueFactory.GetUnsavedIdentifierValue(String unsavedValue, IGetter identifierGetter, IType identifierType, ConstructorInfo constructor) +644

[MappingException: Could not parse identifier unsaved-value: 0]
   NHibernate.Engine.UnsavedValueFactory.GetUnsavedIdentifierValue(String unsavedValue, IGetter identifierGetter, IType identifierType, ConstructorInfo constructor) +872
   NHibernate.Tuple.PropertyFactory.BuildIdentifierProperty(PersistentClass mappedEntity, IIdentifierGenerator generator) +220
   NHibernate.Tuple.Entity.EntityMetamodel..ctor(PersistentClass persistentClass, ISessionFactoryImplementor sessionFactory) +696
   NHibernate.Persister.Entity.AbstractEntityPersister..ctor(PersistentClass persistentClass, ICacheConcurrencyStrategy cache, ISessionFactoryImplementor factory) +784
   NHibernate.Persister.Entity.SingleTableEntityPersister..ctor(PersistentClass persistentClass, ICacheConcurrencyStrategy cache, ISessionFactoryImplementor factory, IMapping mapping) +379
   NHibernate.Persister.PersisterFactory.CreateClassPersister(PersistentClass model, ICacheConcurrencyStrategy cache, ISessionFactoryImplementor factory, IMapping cfg) +182
   NHibernate.Impl.SessionFactoryImpl..ctor(Configuration cfg, IMapping mapping, Settings settings, EventListeners listeners) +2117
   NHibernate.Cfg.Configuration.BuildSessionFactory() +189
   FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory() +76

[FluentConfigurationException: An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.

  * Database was not configured through Database method.
]
   FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory() +120
   SharpArch.Data.NHibernate.NHibernateSession.CreateSessionFactoryFor(String[] mappingAssemblies, AutoPersistenceModel autoPersistenceModel, Configuration cfg, IPersistenceConfigurer persistenceConfigurer) in e:\WorkSpaces\Git\SharpArchitecture\Trunk\src\SharpArch\SharpArch.Data\NHibernate\NHibernateSession.cs:328
   SharpArch.Data.NHibernate.NHibernateSession.AddConfiguration(String factoryKey, String[] mappingAssemblies, AutoPersistenceModel autoPersistenceModel, Configuration cfg, String validatorCfgFile, IPersistenceConfigurer persistenceConfigurer) in e:\WorkSpaces\Git\SharpArchitecture\Trunk\src\SharpArch\SharpArch.Data\NHibernate\NHibernateSession.cs:138
   SharpArch.Data.NHibernate.NHibernateSession.AddConfiguration(String factoryKey, String[] mappingAssemblies, AutoPersistenceModel autoPersistenceModel, String cfgFile, IDictionary`2 cfgProperties, String validatorCfgFile, IPersistenceConfigurer persistenceConfigurer) in e:\WorkSpaces\Git\SharpArchitecture\Trunk\src\SharpArch\SharpArch.Data\NHibernate\NHibernateSession.cs:126
   SharpArch.Data.NHibernate.NHibernateSession.Init(ISessionStorage storage, String[] mappingAssemblies, AutoPersistenceModel autoPersistenceModel, String cfgFile, IDictionary`2 cfgProperties, String validatorCfgFile, IPersistenceConfigurer persistenceConfigurer) in e:\WorkSpaces\Git\SharpArchitecture\Trunk\src\SharpArch\SharpArch.Data\NHibernate\NHibernateSession.cs:101
   SharpArch.Data.NHibernate.NHibernateSession.Init(ISessionStorage storage, String[] mappingAssemblies, AutoPersistenceModel autoPersistenceModel, String cfgFile) in e:\WorkSpaces\Git\SharpArchitecture\Trunk\src\SharpArch\SharpArch.Data\NHibernate\NHibernateSession.cs:51
   SharpDemo.Web.MvcApplication.InitializeNHibernateSession() in D:\Web\Mvc\Projects\Temp\SharpDemo\app\SharpDemo.Web\Global.asax.cs:85
   SharpDemo.Web.MvcApplication.<Application_BeginRequest>b__3() in D:\Web\Mvc\Projects\Temp\SharpDemo\app\SharpDemo.Web\Global.asax.cs:76
   SharpArch.Data.NHibernate.NHibernateInitializer.InitializeNHibernateOnce(Action initMethod) in e:\WorkSpaces\Git\SharpArchitecture\Trunk\src\SharpArch\SharpArch.Data\NHibernate\NHibernateInitializer.cs:46
   SharpDemo.Web.MvcApplication.Application_BeginRequest(Object sender, EventArgs e) in D:\Web\Mvc\Projects\Temp\SharpDemo\app\SharpDemo.Web\Global.asax.cs:75
   System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +68
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75
[格式异常:Guid应包含32位数字和4个破折号(xxxxxxxx-xxxx-xxxx-xxxx-XXXXXXXXXXXXXXXX)。]
System.Guid..ctor(字符串g)+2486
NHibernate.Type.GuidType.FromStringValue(字符串xml)+75
NHibernate.Type.GuidType.StringToObject(字符串xml)+86
NHibernate.Engine.UnsavedValueFactory.GetUnsavedIdentifierValue(字符串unsavedValue,IGetter identifierGetter,IType identifierType,ConstructorInfo构造函数)+644
[MappingException:无法分析标识符未保存的值:0]
NHibernate.Engine.UnsavedValueFactory.GetUnsavedIdentifierValue(字符串unsavedValue,IGetter identifierGetter,IType identifierType,ConstructorInfo构造函数)+872
NHibernate.Tuple.PropertyFactory.BuildIdentifierProperty(PersistentClass MapPedenty,IIIdentifierGenerator生成器)+220
NHibernate.Tuple.Entity.EntityMetamodel..ctor(PersistentClass PersistentClass,ISessionFactoryImplementor sessionFactory)+696
NHibernate.Persister.Entity.AbstractEntityPersister..ctor(PersistentClass PersistentClass,ICACHEConcurrentyStrategy缓存,ISessionFactoryImplementor工厂)+784
NHibernate.Persister.Entity.SingleTableEntityPersister..ctor(PersistentClass PersistentClass,ICACHEConcurrentyStrategy缓存,ISessionFactoryImplementor工厂,IMapping映射)+379
NHibernate.Persister.PersisterFactory.CreateClassPersister(PersistentClass模型、ICACHEConcurrentyStrategy缓存、ISessionFactoryImplementor工厂、IMapping cfg)+182
NHibernate.Impl.SessionFactoryImpl..ctor(配置cfg、映像映射、设置、事件侦听器)+2117
NHibernate.Cfg.Configuration.BuildSessionFactory()+189
FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory()+76
[FluentConfigurationException:创建SessionFactory时使用了无效或不完整的配置。有关详细信息,请检查潜在原因集合和InnerException。
*未通过数据库方法配置数据库。
]
FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory()+120
e:\WorkSpaces\Git\SharpArchitecture\Trunk\src\SharpArch\SharpArch.Data\NHibernateSession\NHibernateSession.CreateSessionFactoryFor(字符串[]映射程序集、AutoPersistenceModel AutoPersistenceModel、配置cfg、IPersistenceConfigurator persistenceConfigurer)
SharpArch.Data.NHibernate.NHibernateSession.AddConfiguration(String factoryKey、String[]映射程序集、AutoPersistenceModel AutoPersistenceModel、Configuration cfg、String validatorCfgFile、IPersistenceConfigurator PersistenceConfigurator)在e:\WorkSpaces\Git\SharpArchitecture\Trunk\src\SharpArch\SharpArch.Data\NHibernate\NHibernateSession.cs:138中
SharpArch.Data.NHibernate.NHibernateSession.AddConfiguration(字符串工厂键、字符串[]映射程序集、AutoPersistenceModel AutoPersistenceModel、字符串cfgFile、IDictionary`2 CFGProperty、字符串验证器cfgFile、IPersistenceConfigurer持久配置器)在e:\WorkSpaces\Git\SharpArchitecture\Trunk\src\SharpArch\SharpArch.Data\NHibernate\NHibernateSession.cs:126中
SharpArch.Data.NHibernate.NHibernateSession.Init(ISessionStorage存储,字符串[]映射程序集,AutoPersistenceModel AutoPersistenceModel,字符串cfgFile,IDictionary`2 CFGProperty,字符串验证程序cfgFile,IPersistenceConfigurer persistenceConfigurer)在e:\WorkSpaces\Git\SharpArchitecture\Trunk\src\SharpArch\SharpArch.Data\NHibernate\NHibernateSession.cs:101中
e:\WorkSpaces\Git\SharpArchitecture\Trunk\src\SharpArch\SharpArch.Data\NHibernateSession.Init(ISessionStorage,String[]映射程序集,AutoPersistenceModel AutoPersistenceModel,String cfgFile)中的SharpArch.Data.NHibernate.NHibernateSession.Init(ISessionStorage,String[]映射程序集,AutoPersistenceModel AutoPersistenceModel,String cfgFile)
D:\Web\Mvc\Projects\Temp\SharpDemo\app\SharpDemo.Web\Global.asax.cs:85中的SharpDemo.Web.mvcapapplication.InitializeNHibernateSession()
D:\Web\Mvc\Projects\Temp\SharpDemo\app\SharpDemo.Web\Global.asax.cs:76中的SharpDemo.Web.mvcapapplication.b\uu 3()
e:\WorkSpaces\Git\SharpArchitecture\Trunk\src\SharpArch\SharpArch.Data\NHibernate\NHibernateInitializer.InitializeNHibernateOnce(操作初始化方法)中的SharpArch.Data.NHibernate.NHibernateInitializer.initializenHibernateInitializer(操作初始化方法):46
D:\Web\Mvc\Projects\Temp\SharpDemo\app\SharpDemo.Web\Global.asax.cs:75中的SharpDemo.Web.mvcapapplication.Application_BeginRequest(对象发送方,事件参数e)
System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()+68
System.Web.HttpApplication.ExecuteStep(IExecutionStep步骤,布尔值&同步完成)+75

自动映射似乎将未保存的值设置为0。尝试将映射覆盖更改为:

mapping.Id(x=>x.Id).GeneratedBy.GuidComb().Default(Guid.Empty)


看起来自动映射正在将未保存的值设置为0。尝试将映射覆盖更改为:

mapping.Id(x=>x.Id).GeneratedBy.GuidComb().Default(Guid.Empty)


谢谢你的反馈。我在追加.Default(Guid.Empty)时遇到了相同的错误,但这使我尝试了.UnsavedValue(Guid.NewGuid()),它似乎已经解决了问题。谢谢你,詹姆斯。哦,我的错。谢谢你的关注和更新。我为其他人找到了这个问题的答案。对于Guid PKs,NHibernate应默认使用未保存的Guid.Empty值。是的。不幸的是,Fluent NH在生成映射时显式重写了未保存的值。感谢您的反馈。我在追加.Default(Guid.Empty)时遇到了相同的错误,但这使我尝试了.UnsavedValue(Guid.NewGuid()),它似乎已经解决了问题。谢谢你,詹姆斯。哦,我的错。谢谢你的关注和更新。我为其他人找到了这个问题的答案。诚实的Fl
Line 83:         private void InitializeNHibernateSession()
Line 84:         {
Line 85:             NHibernateSession.Init(
Line 86:                 webSessionStorage,
Line 87:                 new string[] { Server.MapPath("~/bin/SharpDemo.Data.dll") },
[FormatException: Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).]
   System.Guid..ctor(String g) +2486
   NHibernate.Type.GuidType.FromStringValue(String xml) +75
   NHibernate.Type.GuidType.StringToObject(String xml) +86
   NHibernate.Engine.UnsavedValueFactory.GetUnsavedIdentifierValue(String unsavedValue, IGetter identifierGetter, IType identifierType, ConstructorInfo constructor) +644

[MappingException: Could not parse identifier unsaved-value: 0]
   NHibernate.Engine.UnsavedValueFactory.GetUnsavedIdentifierValue(String unsavedValue, IGetter identifierGetter, IType identifierType, ConstructorInfo constructor) +872
   NHibernate.Tuple.PropertyFactory.BuildIdentifierProperty(PersistentClass mappedEntity, IIdentifierGenerator generator) +220
   NHibernate.Tuple.Entity.EntityMetamodel..ctor(PersistentClass persistentClass, ISessionFactoryImplementor sessionFactory) +696
   NHibernate.Persister.Entity.AbstractEntityPersister..ctor(PersistentClass persistentClass, ICacheConcurrencyStrategy cache, ISessionFactoryImplementor factory) +784
   NHibernate.Persister.Entity.SingleTableEntityPersister..ctor(PersistentClass persistentClass, ICacheConcurrencyStrategy cache, ISessionFactoryImplementor factory, IMapping mapping) +379
   NHibernate.Persister.PersisterFactory.CreateClassPersister(PersistentClass model, ICacheConcurrencyStrategy cache, ISessionFactoryImplementor factory, IMapping cfg) +182
   NHibernate.Impl.SessionFactoryImpl..ctor(Configuration cfg, IMapping mapping, Settings settings, EventListeners listeners) +2117
   NHibernate.Cfg.Configuration.BuildSessionFactory() +189
   FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory() +76

[FluentConfigurationException: An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.

  * Database was not configured through Database method.
]
   FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory() +120
   SharpArch.Data.NHibernate.NHibernateSession.CreateSessionFactoryFor(String[] mappingAssemblies, AutoPersistenceModel autoPersistenceModel, Configuration cfg, IPersistenceConfigurer persistenceConfigurer) in e:\WorkSpaces\Git\SharpArchitecture\Trunk\src\SharpArch\SharpArch.Data\NHibernate\NHibernateSession.cs:328
   SharpArch.Data.NHibernate.NHibernateSession.AddConfiguration(String factoryKey, String[] mappingAssemblies, AutoPersistenceModel autoPersistenceModel, Configuration cfg, String validatorCfgFile, IPersistenceConfigurer persistenceConfigurer) in e:\WorkSpaces\Git\SharpArchitecture\Trunk\src\SharpArch\SharpArch.Data\NHibernate\NHibernateSession.cs:138
   SharpArch.Data.NHibernate.NHibernateSession.AddConfiguration(String factoryKey, String[] mappingAssemblies, AutoPersistenceModel autoPersistenceModel, String cfgFile, IDictionary`2 cfgProperties, String validatorCfgFile, IPersistenceConfigurer persistenceConfigurer) in e:\WorkSpaces\Git\SharpArchitecture\Trunk\src\SharpArch\SharpArch.Data\NHibernate\NHibernateSession.cs:126
   SharpArch.Data.NHibernate.NHibernateSession.Init(ISessionStorage storage, String[] mappingAssemblies, AutoPersistenceModel autoPersistenceModel, String cfgFile, IDictionary`2 cfgProperties, String validatorCfgFile, IPersistenceConfigurer persistenceConfigurer) in e:\WorkSpaces\Git\SharpArchitecture\Trunk\src\SharpArch\SharpArch.Data\NHibernate\NHibernateSession.cs:101
   SharpArch.Data.NHibernate.NHibernateSession.Init(ISessionStorage storage, String[] mappingAssemblies, AutoPersistenceModel autoPersistenceModel, String cfgFile) in e:\WorkSpaces\Git\SharpArchitecture\Trunk\src\SharpArch\SharpArch.Data\NHibernate\NHibernateSession.cs:51
   SharpDemo.Web.MvcApplication.InitializeNHibernateSession() in D:\Web\Mvc\Projects\Temp\SharpDemo\app\SharpDemo.Web\Global.asax.cs:85
   SharpDemo.Web.MvcApplication.<Application_BeginRequest>b__3() in D:\Web\Mvc\Projects\Temp\SharpDemo\app\SharpDemo.Web\Global.asax.cs:76
   SharpArch.Data.NHibernate.NHibernateInitializer.InitializeNHibernateOnce(Action initMethod) in e:\WorkSpaces\Git\SharpArchitecture\Trunk\src\SharpArch\SharpArch.Data\NHibernate\NHibernateInitializer.cs:46
   SharpDemo.Web.MvcApplication.Application_BeginRequest(Object sender, EventArgs e) in D:\Web\Mvc\Projects\Temp\SharpDemo\app\SharpDemo.Web\Global.asax.cs:75
   System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +68
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75
mapping.Id(x => x.Id).GeneratedBy.GuidComb().UnsavedValue(Guid.Empty);