fluent-nhibernate

QueryOver ProjectionList with different root entity types

▼魔方 西西 提交于 2019-12-11 10:36:27
问题 I'm having issues trying to reuse ProjectionLists in NHibernate QueryOvers. I can't work out how to reuse things for different root entities. Object model is roughly represented as: Breakfast one to many Pastry many to zero-or-one Coffee The two separate queries are roughly: session.QueryOver<Breakfast>() .Where(b => b.Id == searchId) .Inner.JoinQueryOver(b => b.Pastries, () => pastry) .Left.JoinAlias(p => p.Coffee, () => coffee) .Select(projections) .TransformUsing(Transformers.AliasToBean

Issue With Fluent Nhibernate Automapping and Guids / UniqueIdentifiers as Primary Key Fields

爱⌒轻易说出口 提交于 2019-12-11 10:19:48
问题 I am attempting to use the Fluent-NHibernate automapping functionality (in the latest version of the software) and am running into problems using Guids as the Primary Key fields. If I use integer fields for the primary keys, the tables are generated successfully and all Nhibernate functionality seems to work fine. FYI, I am using NHibernate to generate my database tables. Here are a couple of classes with integer IDs. using System; using System.Collections; using System.Collections.Generic;

NHibernate.MappingException : No persister for: System.Int32

陌路散爱 提交于 2019-12-11 09:50:31
问题 I have the following... public class TempCartMap : ClassMap<TempCart> { Id(x => x.Id).GeneratedBy.Identity(); ... HasMany(x => x.Products) .Inverse().Cascade.AllDeleteOrphan() .Table("tblCartProducts") .Element("ProductId").KeyColumn("CartId").AsBag(); } [Serializable] public class TempCart { public TempCart(){ Products = new List<int>(); } public virtual IList<int> Products { get; set; } } And a persistance specification: [Test] public void CanMapSaleCart() { SystemTime.Freeze(); IList<int>

FluentNHibernate: LazyLoad and Fetch

故事扮演 提交于 2019-12-11 09:47:46
问题 in fluent nhibernate I can set Fetch.Something and Not.LazyLoad to a Reference or HasMany. What will happen if I use both? How these two reflects to querying data in these three ways? class UserMap { HasMany(x=>x.Contacts). (Fetch or Not.LazyLoad) References(x=>x.Supervisor). (Fetch or Not.LazyLoad) } session.Query<User>(); session.Query<User>().FetchMany(x=>x.Contacts); session.Get<User>(ID); 回答1: The problem is that Fetch is not taken into account for Query/HQL. So, immediately after

Moving from EF to Fluent NHibernate: Memory Leaks, Architecture

爷,独闯天下 提交于 2019-12-11 09:09:15
问题 Good afternoon, I'm migrating a fairly large project over to Fluent NHibernate for use with mono. I've gotten most of the key functionality working well, however I'm having a memory issue. Currently, this code is in two of my controllers. This, does not seem even slightly optimal. But I'm unsure where to put this. private static ISessionFactory CreateSessionFactory() { return Fluently.Configure() .Database(MySQLConfiguration.Standard.ConnectionString( c => c.FromConnectionStringWithKey(

Fluent NHibernate Polymorphic Mapping Challenges

纵饮孤独 提交于 2019-12-11 08:17:24
问题 I am having some problems mapping the following scenario in Fluent Nhibernate using Table Per Concrete class: Let's say I have the following class definitions: public class Reading { .... } public class CarReading : Reading { .... } public class TruckReading : Reading { .... } public class Alert { .... public virtual Reading AReading { get; set; } } So my question is how to create the mapping class for Alert, if it has a one to one relationship with reading class (could be either truck

Fluent NHibernate - How map an IList<Enum> as list of strings

心不动则不痛 提交于 2019-12-11 08:13:09
问题 I have a class with IList<Role> roles as a property which is mapped by the following code: map.HasMany(u=>u.roles).Element("role").Cascade.All() but this maps roles to a column of int but I want it to be mapped to a column of string . 回答1: use the override to specify the NHibernate.Type explicitly .Element("role", e => e.Type<NHibernate.Type.EnumStringType<Role>>()) 来源: https://stackoverflow.com/questions/19597088/fluent-nhibernate-how-map-an-ilistenum-as-list-of-strings

How to make one to one mapping to respect parent/owner object's batching in Fluent nHibernate?

烈酒焚心 提交于 2019-12-11 08:07:55
问题 I have following mapping public class FilmMap : ClassMap<Film> { public FilmMap() { Id(x => x.FilmId, "film_id"); Map(x => x.Description); base.HasMany<FilmActor>(x => x.FilmActor).BatchSize(100); } } public class FilmActorMap : ClassMap<FilmActor> { public FilmActorMap() { Table("film_actor"); CompositeId() //.KeyReference(x => x.Actor, "actor_id") .KeyProperty(x => x.ActorId, "actor_id") .KeyProperty(x => x.FilmId, "film_id"); Map(x => x.LastUpdate, "last_update"); References<Actor>(x => x

LINQ to NHibernate can't get to children's children

别来无恙 提交于 2019-12-11 08:05:03
问题 I have entity A which has an IList of B called Bs and B has an IList of C called Cs. I want to search for all A's which have at least 5 C's in them. So I went and wrote using (var s = this._sessionFactory.OpenSession()) { IQueryable<A> q = s.Linq<A>(); // some code... if (range.Min.HasValue) q = q.Where(a => a.Bs.Sum(b => b.Cs.Count) >= range.Min.Value); // some code... return q.Select(b=>b).ToArray(); } However upon executing the code (and having Min specified in the range variable) I get

Join table in mapping with inverse FK

这一生的挚爱 提交于 2019-12-11 07:54:36
问题 Assume I have two tables: Table MY_ENTITY ID: PK OTHER_ID: FK to table OTHER Table OTHER ID: PK COL: The column I want My entity looks like this: class MyEntity : Entity { public virtual Column { get; set; } } My auto-mapping override looks like this: mapping.IgnoreProperty(x => x.Column); mapping.Join("OTHER", x => x.KeyColumn("ID").Optional() .Map(y => y.Column, "COL"); This works fine and executes without problems, but the join is wrong. It creates an SQL statement that joins the PK of MY