fluent-nhibernate

Fluent nhibernate: How do I map an entity with a property who's type is an interface?

て烟熏妆下的殇ゞ 提交于 2020-01-01 06:49:09
问题 I have an entity like: public class Employee { public int ID { get; set; } public IAccountManager AccountManager { get; set; } ... } I also have a mapping defined for "DefaultAccountManager" - a concrete implementation of IAccountManager. When mapping the above "Employee" entity, how do I tell NHibernate to persist/load the AccountManager property using the mapping defined in "DefaultAccountManager"? Edit: Actually if I could setup a mapping for IAccountManager so that NHibernate could just

NHibernate - How to map to a class that has no table (for custom sql queries)

让人想犯罪 __ 提交于 2020-01-01 04:23:07
问题 Update - Edited config for readability in SO Hi, I've been learning NHibernate for a day or two but getting stuck on one point. I need to be able to execute custom stored procedures and use NHibernate to map them back to domain classes. I have this working for the scenario where the custom query maps back to a object that maps to a database table, as shown by many a nhibernate example (See first section below). However in the config for the second section below, the query pulls only 2 columns

NHibernate IQueryable collection as property of root

大憨熊 提交于 2020-01-01 04:15:05
问题 I have a root object that has a property that is a collection. For example: I have a Shelf object that has Books. // Now public class Shelf { public ICollection<Book> Books {get; set;} } // Want public class Shelf { public IQueryable<Book> Books {get;set;} } What I want to accomplish is to return a collection that is IQueryable so that I can run paging and filtering off of the collection directly from the the parent. var shelf = shelfRepository.Get(1); var filtered = from book in shelf.Books

FluentNHibernate filter with parameterized IN clause

早过忘川 提交于 2020-01-01 03:13:17
问题 In Fluent NHibernate, is it possible to add a parameter to a filter of type List<int> so that the filter condition generates a WHERE SomeColumn IN (@x, @y, @z) ? My use case is to fetch an invoice and a subset of its lines, given the ID of the invoice and a list of invoice line numbers. I want to eager fetch the lines in the same roundtrip as the invoice. I assume it is done something like this, but I cannot find the correct type declaration for the parameter type: Domain objects: public

HasOne vs References Mapping Fluent NHibernate

不羁岁月 提交于 2020-01-01 02:53:06
问题 This is the first time I am working with FluentNhibernate Mapping and facing a question of how to reference another table. Any help is appreciated: I have several tables named CD_ varname and all these contain two columns - CODE and DESCR. I have one main table called Recipient and it has, say two columns, called ALIVE and SEX, both are of type number, and they reference to the tables CD_ALIVE and CD_SEX. If Alive=1 in the Recipient, then we need to get the code and descr from CD_ALIVE table

Fluent NHibernate + multiple databases

旧巷老猫 提交于 2020-01-01 02:41:27
问题 My project needs to handle three databases, that means three session factories. The thing is if i do something like this with fluent nhibernate: .Mappings(m => m.FluentMappings.AddFromAssembly(Assembly.GetExecutingAssembly())) the factories would pick up all the mappings, even the ones that correspond to another database I've seen that when using automapping you can do something like this, and filter by namespace: .Mappings(m => m.AutoMappings.Add( AutoMap .AssemblyOf<Product>() .Where(t => t

how to achieve table per concrete class when base class is abstract in fluent nhibernate?

这一生的挚爱 提交于 2020-01-01 02:38:26
问题 i have the following scenario public abstract class BaseClass { public virtual int Id {get; set}; public virtual string Name {get; set;} } public class FirstSubClass : BaseClass { //properties and behaviour here } public class SecondSubClass : BaseClass { //properties of SecondSubclass Here } public class ProcessStep { public virtual IList<BaseClass> ContentElements {get; set;} } for mapping i have used following code snippet :- this._sessionFactory = Fluently.Configure().Database

Fluent NHibernate one to many uni-directional mapping

人走茶凉 提交于 2019-12-31 20:06:10
问题 I have Post and Comment classes, and they have a one to many relationship where Post has a list of Comments. How can I map this as a uni-directional relationship with Fluent NHibernate, since a comment does not need to know its parent Post? Currently, this is my mapping for Comment: Id(x => x.Id); Map(x => x.Body); References(x => x.User); and for Post: Id(x => x.Id); Map(x => x.Title); HasMany(x => x.Comments) .Inverse() .WithKeyColumn("PostId") .Cascade.AllDeleteOrphan(); This doesnt work

Class Map Generator for Fluent NHibernate

三世轮回 提交于 2019-12-31 08:44:19
问题 Is there a Class Map generator for Fluent NHibernate? I need something like db2hbm but I want it to generate Fluent Class Maps instead of xml mappings. I am aware of AutoMapping for Fluent but that is not what I want. I want to be able to generate Class Map files from tables in database and push them to my src repository. 回答1: You can do this with NHibernate Mapping Generator. 回答2: You can do this with Visual NHibernate. Check the Fluent Nhibernate option on the Options screen to create FNH

Fluent Nhibernate problem

坚强是说给别人听的谎言 提交于 2019-12-31 04:58:07
问题 I have this in my entity: public virtual Iesi.Collections.Generic.ISet<long> Blas { get; set; } and this for my mapping: mapping.HasMany(x => x.Blas).AsSet().Element("Value", m => m.Type<long>()); This creates the relevant tables and I add data like this: X.Blas = new Iesi.Collections.Generic.HashedSet<long>(); X.Blas.Add(some_long); This adds values to the object but the values in Blas are never persisted (everything else of X is). Can anyone see anything wrong? Thanks. Christian 回答1: if X