nhibernate

How can I use the READPAST hint in NHibernate?

蹲街弑〆低调 提交于 2019-12-24 03:16:31
问题 Is there any way I can get NHibernate to use the READPAST hint when selecting data from SQL Server? 回答1: Option #1 Easy way: SQL query Session.CreateSQLQuery("select * from YourEntityTable with (readpast) where SomeColumn = :col") .AddEntity(typeof(YourEntity)) .SetString("col", value) .UniqueResult<YourEntity>(); Option #2 Requires more work: If you're not using one of NHibernate.LockMode you can override dialect's AppendLockHint() to something like: public override string AppendLockHint

How do I write a generic Save() method that handles single objects and collections?

人盡茶涼 提交于 2019-12-24 03:13:14
问题 I have two generic save methods in a repository class: public void Save<T>(T entity) { _session.Save(entity); } public void Save<T>(IEnumerable<T> entities) { foreach (var item in entities) { _session.Save(item); } } However, when I use Save(collection) (which infers the type automatically), it recognizes it as a T rather than IEnumerable<T> and tries to save it using the first method. How do I write this save method(s) so that it can handle either case, without me having to explicitly

Wcf NHibernate Session management

六眼飞鱼酱① 提交于 2019-12-24 03:01:11
问题 I'm new to Castle, NHibernate and WCF. I implemented the session management for my MVC application based on the following article because it seemd to be the most advanced implementation of all posts I've read so far : http://nhibernate.info/blog/2011/03/02/effective-nhibernate-session-management-for-web-apps.html The only problem I got was that this uses some Asp.net specific functionality that isn't available in my WCF service like (HttpContext.Current.Items). I started to use WcfFacility

NHibernate 3.2 QueryOver distinct by property

我只是一个虾纸丫 提交于 2019-12-24 02:59:14
问题 I have two classes public class News { public virtual int Id { get; protected set; } public virtual string Topic { get; set; } public virtual Category Category { get; set; } } public class Category { public virtual int Id { get; protected set; } public virtual string Name { get; set; } public virtual ISet<News> News { get; set; } } And mappings <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="News" namespace="NewsManagement.Models"> <class name="News" table="News"> <id name="Id

NHibernate Mapping multiple tables to one class

百般思念 提交于 2019-12-24 02:50:06
问题 In my legacy Database I have a situation like this: TableA (id_A[PK], cod_A) TableB (id_B[PK], cod_B, id_A[FK]) TableC (id_C[PK], cod_C, id_B[FK]) For several reasons I need to map these tables into a single class (Foo in this example) public class Foo { public virtual string IdA { get; set; } public virtual string CodA { get; set; } public virtual string IdB { get; set; } public virtual string CodB { get; set; } public virtual string IdC { get; set; } public virtual string CodC { get; set; }

How to use NHibernate and DTOs with RIA Services

陌路散爱 提交于 2019-12-24 02:22:36
问题 I’m using NHibernate with RIA Services and Silverlight 4. I create DTOs for transferring the data via RIA Services rather than distributing my domain layer objects (as per Martin Fowler’s First Law of Distributed Object Design: “Don’t distribute your objects!”). The DTO objects are flattened down to two layers from five corresponding layers in the domain layer. Here’s my problem. After making changes in Silverlight 4, RIA Services knows which DTO objects have been modified, but in the server

Is it true that NHibernate ISession.save(newTransientEntity) will only return generated Id, but NOT updating the Id property of the entity?

安稳与你 提交于 2019-12-24 01:55:09
问题 Using NHibernate.Mapping.Attributes, I have a entity class with something like: [Class] public class EntityA { ... [Id][Generator(class="guid")] public Guid Id {...} [Property] public string Property1 {...} ... } Let say if I add a transient entity to the persistence context with code like this: ... Guid id; using(ISession s = sessionFactory.OpenSession()) using(ITransaction t = s.BeginTransaction()) { EntityA entity = new EntityA(); entity.Property1 = "Some Value"; id = (Guid) s.Save(entity)

How to query NHibernate for specific type?

泄露秘密 提交于 2019-12-24 01:46:07
问题 I'm using Fluent NHibernate with DiscriminateSubClassesOnColumn() to support subclassing. The column used to discriminate between subclasses is not mapped to an actual property on the entity. How do I create a query which returns only entities of a given type? Here's my try, where propertyName is the name of my discriminating column and value is the type name: return _db.CreateCriteria<T>() .Add(Restrictions.Eq(propertyName, value)) .List<T>(); However this gives me the error "could not

nHibernate unable to cast Boolean to String

↘锁芯ラ 提交于 2019-12-24 01:42:32
问题 I have the following query: var query = from item in Session.Query<FactuurItem>() where item.EnergieType == etype && (item.DienstType == null || item.DienstType == DienstType.Onbekend || item.DienstType == dtype) && item.IsActive == true orderby item.Naam select item; Which is converted to the following SQL: select * from [FactuurItem] factuurite0_ where factuurite0_.EnergieType=? and (factuurite0_.DienstType is null or factuurite0_.DienstType=? or factuurite0_.DienstType=?) and case when

QueryOver error : Unrecognised method call in expression value

妖精的绣舞 提交于 2019-12-24 01:25:01
问题 I have a query by QueryOver in Nhibernate3.1 var q = SessionInstance.QueryOver<Person>() .Where(x => IsActive(x.PersonType) == true); return q.List<Person>(); By this method: private bool IsActive(PersonType type) { if(type == PersonType.Employee return true; else return false; } Now it has a runtime error by this message: Unrecognised method call in expression value Why? 回答1: I solved a similar problem by returning an expression tree in my predicate method instead of returning a boolean