fluent-nhibernate

Mapping a list of Enums

空扰寡人 提交于 2019-12-06 00:42:24
I have a table called UserPermissions with a FK to the users table by userId and then a string column for the string value of an enum. The error I am seeing is NHibernate.MappingException: An association from the table UserPermissions refers to an unmapped class: GotRoleplay.Core.Domain.Model.Permission My Permission Enum: public enum Permission { [StringValue("Add User")] AddUser, [StringValue("Edit User")] EditUser, [StringValue("Delete User")] DeleteUser, [StringValue("Add Content")] AddContent, [StringValue("Edit Content")] EditContent, [StringValue("Delete Content")] DeleteContent, } The

Cascade on delete using unidirectional Many-To-Many mapping

非 Y 不嫁゛ 提交于 2019-12-06 00:23:57
I am using Fluent and NHibernate. I have two objects say A & B which has a many-to-many relationship between them. I am using a unidirectional many-to-many mapping when A HasMany B's. There is no reference in B about A (Unidirectional). This creates a third table (named ABMapping) in the Database which has the two columns relating to primary keys of A & B. If I delete the object A, the entries from the ABMapping table related to A are deleted. That's cool. But, now I am not able to delete an object B, as it has a FK constraint. How can I set it up so that on deleting B, all entries related to

Exposing HasMany and ManyToMany relationships as IEnumerable

末鹿安然 提交于 2019-12-05 23:12:03
Currently in my entities I'm exposing my collections as an IList but I've been thinking about exposing them as a IEnumerable to prevent users from manually adding to the collections. I have specific adds for these operations so that I can make sure my bi-directional relationships stay intact. A couple questions come to mind in this scenario. If I expose them as IEnumberable does this mean I'll need an Add and Remove method for every collection that represents a relationship in my entities? Is there an easier way to do this? I'm not against doing it this way just wondering. Are you doing it

Fluent NHibernate: override derived classes not in the base class auto-mapping

人盡茶涼 提交于 2019-12-05 22:47:10
The story: I had class User and class Organization: User. I did not use any mappings for these classes, let FNH do mapping automatically. Then, I added public class OrganizationMap : IAutoMappingOverride<Organization> { public void Override(AutoMap<Organization> mapping) { } } Notice there're no overrides. So I did not expect any changes in FNH behavior. But I got this (during schema export actually): NHibernate.MappingException: (XmlDocument)(2,4): XML validation error: The element 'class' in namespace 'urn:nhibernate-mapping-2.2' has incomplete content. List of possible elements expected:

How to identify a particular entity's Session Factory with Fluent NHibernate and Multiple Databases

天大地大妈咪最大 提交于 2019-12-05 22:45:45
问题 Question follows on from Fluent NHibernate + multiple databases (no need to follow this link,there should be enough background here). My problem is this: I'm using Fluent NHibernate. My application uses multiple databases. Each database has its own entities registered (mapped) against it. The result is that have multiple Session Factories, each one relating to a single DB, and each 'containing' its own set of mapped entities. For loading entities I've created a generic Factory class that

Fluent NHibernate exception moving objects between collections

隐身守侯 提交于 2019-12-05 22:29:01
When moving an object from one collection to another and when cascade is set to all-delete-orphan, I get the following exception: deleted object would be re-saved by cascade (remove deleted object from associations) I thought that nhibernate would not delete an object when it is referenced in another collection when you use all-delete-orphan. Can anyone confirm that, when you have objects like Folders which contain Folders or Files and you move a File from one Folder to another, you should not get this exception? I made a sample project in vs2010 which demonstrates this behavior. Can anyone

Fluent Nhibernate How to specify Id() in SubclassMap

梦想的初衷 提交于 2019-12-05 21:26:04
I'm in the process of adapting Fluent NHibernate to our existing legacy app and am trying to determine how to use ClassMap and SubclassMap for the entity hierarchy shown. // BaseObject contains database columns common to every table public class BaseObject { // does NOT contain database id column public string CommonDbCol1 { get; set; } public string CommonDbCol2 { get; set; } // ... } public class Entity1 : BaseObject { public int Entity1Id { get; set; } // other Entity1 properties } public class Entity2 : BaseObject { public int Entity2Id { get; set; } // other Entity2 properties } The

Fluent NHibernate pattern for both IHttpModule and console apps

[亡魂溺海] 提交于 2019-12-05 21:03:46
I currently have a C# MVC 2 web app using Fluent NHibernate (+ LINQ) in a Repository Pattern and am using Ninject to handle the MVC controller's constructor requirement that it be passed in the repository. My Fluent NHibernate code is currently hooked into an IHttpModule, so the session can be opened and closed with the web request. This works great until I try to hook my domain model into a console app. First, I decided to move my database logic into my domain model. I'm guessing this is bad behavior but I am here asking for help on code design, so please feel free to make suggestions. I

trying to implement session per web request, No current session context configure

送分小仙女□ 提交于 2019-12-05 20:01:10
As I said in the title I want to implement session per web request. My session provider is configured like this (I'm not interested in changing this conf.) public class SessionProvider { public static SessionProvider Instance { get; private set; } private static ISessionFactory _SessionFactory; static SessionProvider() { var provider = new SessionProvider(); provider.Initialize(); Instance = provider; } private SessionProvider() { } private void Initialize() { string csStringName = "ConnectionString"; var cfg = Fluently.Configure() ....ommiting mappings and db conf. .ExposeConfiguration(c => c

Fluent NHibernate - How to map the foreign key column as a property

拥有回忆 提交于 2019-12-05 19:41:09
问题 I am sure this is a straightforward question but consider the following: I have a reference between company and sector as follows: public class Company { public Guid ID { get; set; } public Sector Sector { get; set; } public Guid SectorID { get; set; } } public class Sector { public Guid ID { get; set; } public string Name { get; set; } } Ok. What I want is the SectorID of the Company object to be populated after I go: (new Company()).Sector = new Sector() { Name="asdf" } and do a flush. The