我有几个从非常精细的表中读取的类,这就是为什么我希望NHibernate将它们用作“ReadOnly”。在每个字段映射上建立.ReadOnly()真的很草率,我不确定我是否相信它。如何将一个类设置为完全只读的,就像我可以轻松地使用传统的XML映射一样?编辑:答案确实有效。如果我试图保存一个ReadOnly()对象,我预计它会抛出异常,但它只是默默地这样做。谢谢。 最佳答案 使用FluentNHibernate,它非常简单:classEntityMap:ClassMap{publicEntityMap(){ReadOnly();//M
我使用一个简单的拦截器来拦截nhibernate为记录目的生成的sql字符串,它工作正常。publicclassSessionManagerSQLInterceptor:EmptyInterceptor,IInterceptor{NHibernate.SqlCommand.SqlStringIInterceptor.OnPrepareStatement(NHibernate.SqlCommand.SqlStringsql){NHSessionManager.Instance.NHibernateSQL=sql.ToString();returnsql;}}然而,这捕获了没有参数值的sq
我对此很陌生,但我需要从现有类创建新表,而无需手动创建它们。这可以使用工具或命令行来完成吗? 最佳答案 是的,使用nhibernate,您可以自动生成和更新模式。varcfg=newConfiguration();cfg.Configure();cfg.AddAssembly(typeof(aClassFromYourProject).Assembly);newSchemaExport(cfg).Execute(false,true,false,false);更新:SchemaExport.Execute的重载选项在3.x版本中发生
我有一个简单的查询如下:varemployeeTeam=Session.Query().Where(x=>x.StartEffective.OrderByDescending(x=>x.StartEffective).Select(x=>new{x.EmployeeId,x.StartEffective,x.Team}).ToList();它成功运行了一次,但是在第二次执行时(或第三次、第四次等等)它抛出了一个无效的转换异常,例如:FatalError:System.InvalidCastException:Cannotconverttype'System.Linq.Enumerabl
这是我的映射类:classMyTableMap:ClassMap{publicMyTableMap(){Schema("mySchema");Id(x=>x.id);Map(x=>x.SomeString);}}这适用于我的第一个数据库中的表([mySchema].[MyTable])。但是这个表(“MyTable”)存在于(实际上很多)不同的数据库中,但是由于任何原因,模式总是被命名为不同的(我无法控制):因此在数据库“OtherDB”中有表[SomeOtherSchema].[MyTable],其结构与第一个数据库中的[mySchema].[MyTable]相同。出于显而易见的原因
在项目中升级NHibernate和FluentNHibernateDLL后,我现在在初始化SessionFactory时收到“无法确定类型:MyApp.Domain.Entities.AppCategory”异常抛出。我的代码中唯一的变化是调整ForeignKeyConvention的实现以覆盖GetKeyName(Membermember,Typetype)抽象方法,而不是GetKeyName(PropertyInfoproperty,Typetype).FluentNHibernate的升级DLL从1.0.0.593到1.1.0.685,NHibernate从2.1.0.4000到
.NET4ISetHashSet可以替换NHibernateIesi.CollectionsISet、HashSet吗?我正在使用CaSTLe代理和NHibernate3.0。 最佳答案 是的。有两种方法:将您的收藏声明为ICollection并将其初始化为HashSet.参见thisarticle.我将集合建模为私有(private)成员并公开IEnumerable所以这很好用,但缺点是你不能公开ISet.使用JoseRomaniello的Set4Net4NuGet包。参见thisarticle和sourcecode.
如何进行一对一映射。publicclassSetting{publicvirtualGuidStudentId{get;set;}publicvirtualDateFiltersTaskFilterOption{get;set;}publicvirtualstringTimeZoneId{get;set;}publicvirtualstringTimeZoneName{get;set;}publicvirtualDateTimeEndOfTerm{get;set;}publicvirtualStudentStudent{get;set;}}设置类图:publicSettingMap()
我遇到了这个异常(底部的完整异常):NHibernate.PropertyValueExceptionwasunhandledbyusercodeMessage="not-nullpropertyreferencesanullortransientvalueClearwave.Models.Encounters.Insurance.Patient"Source="NHibernate"EntityName="Clearwave.Models.Encounters.Insurance"PropertyName="Patient"我已经进行了大量的谷歌搜索,这似乎是最常见的原因该错误是当关
StatelessSession和NHibernate中的Session有什么区别? 最佳答案 无状态session不跟踪检索到的实体。例如对于常规ISession以下代码:varsession=sessionFactory.OpenSession()using(vartransaction=session.BeginTransaction()){varuser=session.Get(1);user.Name="changedname";transaction.Commit();}将导致数据库更新。这种跟踪会消耗内存并使ISess