fluent-nhibernate

How to add event listener via Fluent NHibernate?

和自甴很熟 提交于 2019-12-06 17:14:04
问题 I want to add an event listener ( IPreUpdateEventListener ) to add NHibernate but I can't seem to find an example when using a fluent configuration. I want to be able to add the listener when I create the session factory, e.g. when the following code is execute. _sessionFactory = Fluently.Configure() .Database(MsSqlConfiguration.MsSql2005.ConnectionString(connectionString).ShowSql()) .Mappings(m => m.FluentMappings.AddFromAssemblyOf<IEntity>()) .BuildSessionFactory(); Anyone know how to do

Fluent NHibernate Many to Many with extra column does not insert

好久不见. 提交于 2019-12-06 16:49:14
I'm struggling with fluent nhibernate from Fluent Nhibernate Many-to-Many mapping with extra column I've copied the mappings and written the smallest program I can... but it wont save... Would anybody be able to provide some insight ??? public class Product { public int Id { get; set; } public string Name { get; set; } public IList<Inventory> Inventory { get; set; } public Product() { Inventory = new List<Inventory>(); } } public class Warehouse { public int Id { get; set; } public string Name { get; set; } public IList<Inventory> Inventory { get; set; } public Warehouse() { Inventory = new

FluentNhibernate support for SQL Server 2008 R2

孤者浪人 提交于 2019-12-06 16:10:17
问题 I want to implement a Fluent Nhibernate application with SQL Server 2008 R2. I am in a confusion whether Fluent Nhibernate 1.2 supports SQL Server 2008 R2. If supports what will be the configuration. Does it looks like below? var config = Fluently.Configure() .Database( MsSqlConfiguration .MsSql2008R2 .ConnectionString(@"Data Source=.\SQLEXPRESS;AttachDbFilename='FNHLD.mdf';Integrated Security=True;User Instance=True")) .Mappings(m => m.FluentMappings.AddFromAssemblyOf<NHibernateRepository<T>

Fluent NHibernate Newbie: Row was updated or deleted by another transaction

旧巷老猫 提交于 2019-12-06 15:49:47
I'm in the early stages of building out a database with Fluent NHibernate. I implemented a unit-of-work pattern in ASP.NET MVC 3 to let NHibernate update my database schema for me. To insert/update my initial data, I have a Database controller with an Update action that tries to SaveOrUpdate(...) a User entity (the administrator user) into the Users table. After manually deleting all user records via Visual Studio and re-running my Update action to repopulate the Users table, I receive the following NHibernate.StaleObjectStateException exception: Row was updated or deleted by another

Fluent Nhibernate HasMany mapping issue

北战南征 提交于 2019-12-06 14:43:18
I'm new to Fluent and NHibernate and I'm not sure how to map this specific relationship that exists in my database. I have the following ER diagram below that outlines my table structure. Below are my current C# entity classes: public class GroupHeader { public virtual Guid Id { get; private set;} public virtual string Name { get; set; } public virtual string Description { get; set; } public virtual IList<RightHeader> Rights { get; set; } public virtual IList<GroupRight> GroupRights { get; set; } public GroupHeader() { GroupRights = new List<GroupRight>(); Rights = new List<RightHeader>(); }

Fluent NHibernate Inheritance mapping type

故事扮演 提交于 2019-12-06 14:38:12
I'm new to Fluent NHibernate, thus far I managed to get my mapping working except for the inheritance part. Is there anybody who could help me finish the mapping? I have simplified the code as much as possible. Thank you! My database: CREATE TABLE [User] ( UserID INT NOT NULL IDENTITY(1,1), Type CHAR(1) NOT NULL, Email VARCHAR(255) NOT NULL, PRIMARY KEY(UserID) ); CREATE TABLE [Student] ( UserID INT NOT NULL, Firstname VARCHAR(255) NOT NULL, PRIMARY KEY(UserID), FOREIGN KEY(UserID) REFERENCES [User](UserID) ); CREATE TABLE [Company] ( UserID INT NOT NULL, Name VARCHAR(255) NOT NULL, PRIMARY

Fluent NHibernate Custom Type convention for bools

自作多情 提交于 2019-12-06 14:26:44
Trying to create a convention that applies to all bool properties. Given this class: public class Product { public string Name { get; private set; } public bool IsActive { get; private set; } public Product(string name) { Name = name; } } I have a mapping like: public class ProductMap : ClassMap<Product> { public ProductMap() { Map(x => x.Name); Map(x => x.IsActive).CustomType<YesNoType>(); } } I would like to have a convention that does this. So far I have: public class YesNoTypeConvention : IPropertyConvention, IPropertyConventionAcceptance { public void Apply(IPropertyInstance instance) {

NHibernate config properties in Fluent NHibernate

北城以北 提交于 2019-12-06 14:07:39
I am considering using Fluent NHibernate for my project and I haven't found any documentation on whether FH supports NHibernate settings such as show_sql and prepare_sql. I could live without show_sql in a pinch, but prepare_sql is important for ensuring good performance at run time. Can anyone tell me if it's possible to configure these settings in Fluent NHibernate? Yes, you can. Fluently.Configure() .Database(ConfigureDatabase()) .Mappings(ConfigureMapping) .ExposeConfiguration(ModifyConfiguration) .BuildConfiguration(); And now in ModifyConfiguration method you have plain NHibernate 's

How do I map a dictionary using Fluent NHibernate automapping?

大憨熊 提交于 2019-12-06 13:39:19
I have an entity like so: public class Land { public virtual IDictionary<string, int> Damages { get; set; } // and other properties } Every time I try to use automapping with the following code: var sessionFactory = Fluently.Configure() .Database(SQLiteConfiguration.Standard.InMemory) .Mappings(m => m.AutoMappings.Add(AutoMap.AssemblyOf<Land>)) .BuildSessionFactory(); I get the following error: {"The type or method has 2 generic parameter(s), but 1 generic argument(s) were provided. A generic argument must be provided for each generic parameter."} Can someone tell me what I'm doing wrong? Also

Geospatial Point Mapping in Fluent NHibernate

ぃ、小莉子 提交于 2019-12-06 13:36:08
问题 I'm struggling to get Fluent NHibernate to play nice with SQL Server's Geospatial types. I want to store a geographic point in my Place class, but I keep getting an NHibernate configuration error when I run my ASP.NET MVC app: Method 'SetParameterValues' in type 'NHibernate.Spatial.Type.GeometryType' from assembly 'NHibernate.Spatial, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' does not have an implementation. Update : This is caused by an out-dated NHibernate.Spatial DLL.