fluent-nhibernate

Mapping interface or abstract class component

纵饮孤独 提交于 2019-12-04 13:26:24
问题 Please consider the following simple use case: public class Foo { public virtual int Id { get; protected set; } public virtual IBar Bar { get; set; } } public interface IBar { string Text { get; set; } } public class Bar : IBar { public virtual string Text { get; set; } } And the fluent-nhibernate map class: public class FooMap : ClassMap<Foo> { public FooMap() { Id(x => x.Id); Component(x => x.Bar, m => { m.Map(x => x.Text); }); } } While running any query with configuration, I get the

Experience with fluent interfaces? I need your opinion!

≯℡__Kan透↙ 提交于 2019-12-04 12:47:28
Sorry for this long question, it is flagged wiki since I'm asking for something that might not have a very concrete answer. If it is closed, so be it. My main question is this: How would you write a fluent interface that isn't fully defined in the base classes, so that programs that uses the fluent interfaces can tack on new words inside the existing structure, and still maintain a guiding interface so that after a dot, the intellisense only lists the keywords that actually apply at this point. I'm on my 3rd iteration of rewriting my IoC container. The 2nd iteration was to improve performance,

Fluent mapping - entities and classmaps in different assemblies

坚强是说给别人听的谎言 提交于 2019-12-04 12:44:06
When using fluent configuration to specify fluent mappings like this: .Mappings(m => m.FluentMappings.AddFromAssembly(typeof(UserMapping).Assembly)) At the moment I am getting a "NHibernate.MappingException : No persister for" error. Is it a problem that my Entities and my ClassMaps are in different assemblies? Presumably AddFromAssembly is interested in the assembly that holds the class maps, not the entities? (that is what I have assumed) Thanks! UPDATE: Sorry for not responding to answers very quickly - I had to travel unexpectedly after setting the bounty. Anyway, thanks for the responses.

Map to a list of Enums?

不羁的心 提交于 2019-12-04 12:38:05
I need to map a class which has a list of Enums to a db table, using NHibernate here are the objects public class Driver : IIdentity { private IList<Licence> licences; /// <summary> /// The drivers licences /// </summary> public virtual IList<Licence> Licences { get { return this.licences; } set { this.licences = value; } } ..... rest of the class .... } //the enum public enum Licence { FivePersonCar = 5, SixPersonCar = 6 } ---------------- here is the DB table TABLE [dbo].[DriverLicence]( [DriverId] [int] NOT NULL, [Level] [int] NOT NULL) TABLE [dbo].[Driver]( [DriverId] [int] NOT NULL, [Name

Fluent nhibernate mapping problem: many to many self join with additional data

☆樱花仙子☆ 提交于 2019-12-04 12:29:05
I am struggling with mappings for the following sql tables |Post | |PostRelation | |------------------| |-----------------| |PostId |1--------*|ParentPostId | |---other stuff--- |1--------*|ChildPostId | | | |RelationType | Ideally Id like a property on post called relatedPosts as Dictionary <RelationType,IList<Post>> But at the minute Id just settle for a property on post with an IList<PostRelation>. I successfully used a many to many to get related posts, but this method loses the addtional data. Any suggestions?? I Finally found a solution after much research. So though I would post it in

NHibernate - filtering out results based on child-property

谁说胖子不能爱 提交于 2019-12-04 12:28:28
I have this code fetching all enabled Groups with their children. The problem I have is that the children can also be disabled but I can't get fluent nhibernate to only fetch groups where all childrens are enabled. I assume this is possible but how? public class Group { public bool IsDisabled { get; set; } public string Description { get; set; } public ICollection<ChildType> Children { get; protected set; } } public class ChildType { public bool IsDisabled { get; set; } public string Description { get; set; } } public IList<Group> Search(string searchString) { IQueryOver<Group> query = Session

Fluent NHibernate and filtering one-to-many relationship on query requiring multiple joins?

被刻印的时光 ゝ 提交于 2019-12-04 12:23:26
I recently got started with NHibernate and am having some trouble implementing the domain model outlined further down. What I'm looking for is a way to filter the relationship between an Item and it's ItemData collection on specific DataStores. DataStores are either global, in which case they are always returned, or specific to a user identity (based on application instance). In SQL this can be accomplished using a simple query: SELECT * FROM Items i INNER JOIN ItemData id ON (i.ItemId=id.ItemId) LEFT OUTER JOIN Users u ON (id.UserId=u.UserId) LEFT OUTER JOIN DataStore ds ON (id.DataStoreId=ds

FluentNHibernate: Automapping OneToMany relation using attribute and convention

眉间皱痕 提交于 2019-12-04 12:19:06
问题 This is very similar to my previous question: FluentNHibernate: How to translate HasMany(x => x.Addresses).KeyColumn("PersonId") into automapping Say I have these models: public class Person { public virtual int Id { get; private set; } public virtual ICollection<Address> Addresses { get; private set; } } public class Address { public virtual int Id { get; private set; } public virtual Person Owner { get; set; } } I want FluentNHibernate to create the following tables: Person PersonId Address

Why does this HQL delete fail, when an HQL select with same terms works?

狂风中的少年 提交于 2019-12-04 12:08:06
Why does the following HQL query fail? string hql = @"delete MyLog log where log.UtcTimestamp < :threshold and log.Configuration.Application = :application"; session.CreateQuery(hql) .SetDateTime("threshold", threshold) .SetEnum("application", this.application) .ExecuteUpdate(); The same form of query works when used in a select: string hql = @"from MyLog log where log.UtcTimestamp < :threshold and log.Configuration.Application = :application"; IList<MyLog> log = session.CreateQuery(hql) .SetDateTime("threshold", threshold) .SetEnum("application", this.application) .List<MyLog>(); The mapping

FluentNHibernate Many-To-One References where Foreign Key is not to Primary Key and column names are different

这一生的挚爱 提交于 2019-12-04 11:49:58
问题 I've been sitting here for an hour trying to figure this out... I've got 2 tables (abbreviated): CREATE TABLE TRUST ( TRUSTID NUMBER NOT NULL, ACCTNBR VARCHAR(25) NOT NULL ) CONSTRAINT TRUST_PK PRIMARY KEY (TRUSTID) CREATE TABLE ACCOUNTHISTORY ( ID NUMBER NOT NULL, ACCOUNTNUMBER VARCHAR(25) NOT NULL, TRANSAMT NUMBER(38,2) NOT NULL POSTINGDATE DATE NOT NULL ) CONSTRAINT ACCOUNTHISTORY_PK PRIMARY KEY (ID) I have 2 classes that essentially mirror these: public class Trust { public virtual int Id