fluent-nhibernate

Linq: select property collection

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-04 13:47:08
问题 I have two classes: public class Person { public int Id{get;set;} public string Name{get;set;} public List<Order> Orders{get;set;} } public class Order { public int Id{get;set;} public string Data{get;set;} public decimal Sum{get;set;} } I use Nhibernate Linq. If I want to get total sum of orders filtering by Persan.Name I do this: var result = (from person in personRepository.Query from order in person.Orders where person.Name.Contains("off") select order).Sum(order => order.Sum); How can I

Disabling caching in Fluent Nhibernate for a specific override

僤鯓⒐⒋嵵緔 提交于 2020-01-04 08:12:11
问题 We're using convention based mapping with Fluent NHibernate. The mapping looks like so: .Conventions.Add ( Table.Is(x => string.Concat(x.EntityType.Name.ToLower(), "s")), PrimaryKey.Name.Is(x => "Id"), DefaultLazy.Always(), DefaultCascade.SaveUpdate(), AutoImport.Never(), Cache.Is(x => x.ReadWrite()) ) For most of our objects this is perfect but on certain objects I wish to disable the 2nd level cache. However it doesn't appear that I can do this. There is no fluent option for Cache.None. I

How do I create a NHibernate Mapping file for a multi-value component that is a Unique set of columns?

末鹿安然 提交于 2020-01-04 06:50:11
问题 I'm using NHibernate and Fluent NHibernate to create a mapping file for a domain object (though I don't care if an answer uses fluent NHibernate or xml hbm syntax). And I'm having trouble with figuring out how I specify that a set of columns representing a component within the domain object is unique. Here's the domain object: public class SpaceLocation { public SpaceCoordinate Coordinates { get; set; } public SpaceObject AtLocation { get; set; } } and here is the component I'm having trouble

How to have NHibernate persist a String.Empty property value as NULL

℡╲_俬逩灬. 提交于 2020-01-04 05:16:19
问题 I have a fairly simple class that I want to save to SQL Server via NHibernate (w/ Fluent mappings). The class is made up mostly of optional string fields. My problem is I default the class fields to string.empty to avoid NullRefExceptions and when NHibernate saves the row to the database each column contains an empty string instead of null. Question: Is there a way for me to get NHibernate to automatically save null when the string property is an empty string? Or do I need to litter my code

Fluent NHibernate: How to tell it not to map a base class

自闭症网瘾萝莉.ら 提交于 2020-01-04 04:26:28
问题 I have been googling and stackoverflowing for the last two hours and couldn't find an answer for my question: I'm using ASP.NET MVC and NHibernate and all I'm trying to do is to manually map my entities without mapping its base class. I'm using the following convention: public class Car : EntityBase { public virtual User User { get; set; } public virtual string PlateNumber { get; set; } public virtual string Make { get; set; } public virtual string Model { get; set; } public virtual int Year

Is fluent NHibernate ready for production code?

依然范特西╮ 提交于 2020-01-04 03:49:03
问题 As the title says, I'm wondering if I should avoid using fluent nhibernate for production code, or if it's mature enough to just "dive in"? :) 回答1: The FluentNHibernate API has not yet stabilized and there have not yet been any releases. However, FluentNHibernate is one of those special cases where there is no long-running behavior, only input leading to output. So you can certainly build a fluent mapping between your domain model and your database, inspect the resulting Configuration , and

NHibernate iStatelessSession returns duplicate parent instances on eager fetch

浪子不回头ぞ 提交于 2020-01-04 03:25:31
问题 I'm trying to get a root entity and eager fetch it's child entities. But because I'm using the IStatelessSession of NHibernate, it returns duplicates of the root entity for each child. Using an ISession, it would be solved with .TransformUsing(new DistinctRootEntityResultTransformer()) But for an IStatelessSession it's not. Basically it's about the code below, where there's just one instance of Parent, holding 3 Childs. var result = session.QueryOver<Parent>() .Fetch(i => i.Childs).Eager();

Readonly collection properties that NHibernate can work with

孤街醉人 提交于 2020-01-03 18:51:48
问题 My domain classes have collections that look like this: private List<Foo> _foos = new List<Foo>(); public virtual ReadOnlyCollection<Foo> Foos { get { return _foos.AsReadOnly(); } } This gives me readonly collections that can be modified from within the class (i.e. by using the field _foos). This collection is mapped as follows (Fluent NHibernate): HasMany(x => x.Foos).KeyColumn("ParentClassId").Cascade.All().Inverse().Access.CamelCaseField(Prefix.Underscore); Now when I try to use this

Get table names from Fluent Nhibernate

狂风中的少年 提交于 2020-01-03 10:42:08
问题 After you have setup your mappings in fluent nhibernate, is there a way of getting the table name for an entity from the class type? I have read in regular nhiberante you can do something like cfg.GetClassMapping(typeof (Employee)) . I would like to do the type of thing to retrieve the database table name. Is this possible as standard or how would I go about this? 回答1: The fluent nhibernate way: var userMetadata = sessionFactory.GetClassMetadata(typeof(SomeEntity)) as NHibernate.Persister

How can I map to a joined subclass with a different column than the id of parent?

别来无恙 提交于 2020-01-03 09:14:23
问题 I am working with a brownfield database and am trying to configure a subclass map which joins to its subclasses with a column other than that of the specified id. The login table has a primary key column login_sk which I'd like to use as its id. It joins to two tables via a login_cust_id column (to make things more fun the corresponding columns in the adjoining tables are named differently). If I setup login_cust_id as the id of the UserMap it joins to its subclasses as expected. For what I