fluent-nhibernate

How to configure fluent nHibernate with MySQL

时光怂恿深爱的人放手 提交于 2020-01-20 17:08:27
问题 I'm trying to configure nHibernate to use a MySql database. I found examples for mssql and sqlite but none for mysql. So, how do I change this so it uses mysql: Fluently.Configure().Database( MsSqlConfiguration.MsSql2005.ConnectionString( c => c.FromConnectionStringWithKey("ConnectionString") ) ) .Mappings(m => m.FluentMappings.AddFromAssemblyOf<MyAutofacModule>()) .BuildSessionFactory()) 回答1: Change MsSqlConfiguration.MsSql2005 , to MySqlConfiguration.Standard , it was the one thing I

No Persister for: error on save with INotifyPropertyChanged Interceptor

眉间皱痕 提交于 2020-01-17 08:22:16
问题 Using the method described in NHibernate & INotifyPropertyChanged, the repository will return a collection of proxies that implement INotifyPropertyChanged, but on some objects when saving or deleting it will throw an error: at NHibernate.Impl.SessionFactoryImpl.GetEntityPersister(String entityName) at NHibernate.Impl.SessionImpl.GetEntityPersister(String entityName, Object obj) at NHibernate.Engine.ForeignKeys.IsTransient(String entityName, Object entity, Nullable`1 assumed,

Mapping to a different view based on child type

做~自己de王妃 提交于 2020-01-17 04:27:10
问题 So i have a situation where i have common base type but i need to map to a different view based on the child type. It looks like i can use a generic mapping class to handle the inheritance http://geekswithblogs.net/nharrison/archive/2010/07/09/inheriting-a-class-map-in-fluent-nhibernate.aspx But how can i conditionally map to a different view based on the child type? I see an EntityType property but it says its obsolete and will be made private in the next version. As an example i have a base

could not get a field value by reflection getter… nhibernate query cache with 2nd level cache

不问归期 提交于 2020-01-17 03:16:08
问题 I got this exception could not get a field value by reflection getter of DictionaryMaster. k__BackingField with this inner exception: Field '<>k__BackingField' defined on type is not a field on the target object which is of type 'System.Object[]'. The problem exists only when i use eagerloading in query. Below i put my classes, relations and query. public class DictionaryMaster { public virtual IList<DictionaryItem> DictionaryItems { get; private set; } public virtual System.String Code { get

Fluent NHibernate - Filtering resultset

孤街醉人 提交于 2020-01-16 14:35:09
问题 FNH Newbie question - I have two objects RR and TT defined as following: public class RR { Id Name TT_Id //corresponds to TT.Id } public class TT { Id Name Type } I want to filter records from RR as per following SQL: SELECT RR.* FROM RR LEFT OUTER JOIN TT ON RR.TT_Id = TT.Id WHERE TT.Type <> 7 Can anyone please guide how can I add filter criteria to achieve above in NH. Thank you! 回答1: why you have TT_Id and not TT itself in RR ? IMO it will make a lot of things more difficult than needed.

Setting CustomSqlType on References

一个人想着一个人 提交于 2020-01-16 06:12:49
问题 I have a situation where my primary key is a char(2) in SqlServer 2008, and I want to reference it in a one-to-many relationship, but the ManyToOneBuilder (which is returned by ClassMap<>.References()) doesn't have a CustomSqlType() method. Specifically: public class State { // state FIPS code is 2 characters public virtual string StateCode { get; set; } public virtual ICollection<County> { get; set; } } public class County { // state-county FIPS code is 5 characters public virtual string

Castle Facilities NHibernateIntegration for NHibernate 4.0

痞子三分冷 提交于 2020-01-16 00:50:26
问题 I downloaded the source for NHibernateIntegration from (https://github.com/mahara/Castle.Facilities.NHibernateIntegration) I added reference for Castle.Core (3.3.0.0), Castle.Services.Transaction (3.3.0.0), Castle.Windsor (3.3.0.0), NHibernate (4.0.0.4000) and I built the application to generate the Castle.Facilities.NHibernateIntegration.dll But after the upgrading NHibernateIntegration.dll in my application I am getting the following error, An ISessionFactory component was not mapped for

NHibernate Fluently Configure Default Flush Mode for Session / SessionFactory

≡放荡痞女 提交于 2020-01-15 23:02:44
问题 I am using FluentNHibernate and trying to configure Environment.DefaultFlushMode to FlushMode.Commit According to this SO question it should be possible: How to change default FlushMode to Commit in C#? Indeed, this feature was added https://nhibernate.jira.com/browse/NH-3619 Here is how I use it: public ISessionFactory BootstrapSessionFactory() { return Fluently.Configure() .ExposeConfiguration(cfg => cfg.SetProperty(Environment.DefaultFlushMode, FlushMode.Commit.ToString()))

Map a collection of custom types on fluent nhibernate

╄→尐↘猪︶ㄣ 提交于 2020-01-15 11:14:13
问题 I have a Custom Type on Fluent NHibernate and I need to map it to a collection of its type, using HasMany association. However, Fluent Nhibernate doesn't let me indicate on HasMany that its about a custom type like I do in my regular types. This is my code: HasMany(x => x.AvailablePaymentOptions) .KeyColumn("OFFER_ID") .Cascade.None() .KeyNullable() .Not.LazyLoad(); Any thoughts? Thanks 回答1: Finish not using the custom type, but instead, mapping a component: HasMany(x => x

Fluent Nhibernate: Can't create database connection to MySQL

时光毁灭记忆、已成空白 提交于 2020-01-15 09:41:31
问题 I have been looking into Fluent Nhibernate, and it seems really promising. But... I can't seem to get it working with a MySQL database. I have the Fluent Nhibernate example project running fine with the SQLite database (Fluent NHibernate: Getting Started), but as soon as I change the database configuration to this: return Fluently.Configure() .Database(MySQLConfiguration.Standard.ConnectionString( x => x.Database("database") .Server("server") .Username("login") .Password("password") ) )