nhibernate

NHibernate exception: Transaction not connected, or was disconnected

风格不统一 提交于 2020-01-01 08:21:08
问题 In our develop environment all the ASP.NET application works just fine. However, when I deploy the site on the test machine, on some pages I get this exception: NHibernate.TransactionException: Transaction not connected, or was disconnected at NHibernate.Transaction.AdoTransaction.CheckNotZombied() in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Transaction\AdoTransaction.cs:line 406 at NHibernate.Transaction.AdoTransaction.Rollback() in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Transaction

What does NHibernateUtil.Initialize do?

浪子不回头ぞ 提交于 2020-01-01 08:13:20
问题 I have inherited a piece of code which calls NHibernateUtil.Initialize. I am relatively new to NHibernate and have not been able to work out specifically what calling NHibernateUtil.Initialize does. What does it do and in what scenarios should it be called ? 回答1: Basicaly it will eagerly load the domain objects that are lazily loaded or proxied by nhibernate. Have a look at this from the NHibernate website - lazy-loading-eager-loading the reference is in the bottom quarter of the article. 来源:

Update several Columns in one Hibernate Query?

北慕城南 提交于 2020-01-01 08:02:54
问题 i have the Following HQL: String hql = "UPDATE Buchung as b " + "set STORNO = :Storno " + "where ID = :BuchungID"; Is it possible to Update more then one column in a HQL? For Example: String hql = "UPDATE Buchung as b " + "set STORNO = :Storno " + "set NAME = :Name " + ...... "where ID = :BuchungID"; I know how to do that in MSSQL but i dont know how to do that in Hibernate. 回答1: HQL is no different than SQL in this case. Just use comma to separate columns: String hql = "UPDATE Buchung as b

NHibernate, dependency injection. Close ISession properly

我的梦境 提交于 2020-01-01 06:55:14
问题 I am using Ninject, NHibernate, ASP.NET MVC3 and repository pattern. The module binding in Ninject is as following. Bind<ISessionFactory>().ToProvider(new SessionFactoryProvider()).InSingletonScope(); Bind<ISession>().ToMethod(context => context.Kernel.Get<ISessionFactory>().OpenSession()).InRequestScope(); The question is should the repository take an ISession or ISessionFactory. If it takes an ISessionFactory then in the repository I can open a session when necessary and close it after use.

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

What is Tuplizer in NHibernate

那年仲夏 提交于 2020-01-01 05:12:09
问题 I came across a post that mentioned Tuplizer in NHibernate, can anybody provide a good definition or reference for Tuplizer? 回答1: From ITuplizer's source code: A tuplizer defines the contract for things which know how to manage a particular representation of a piece of data, given that representation's EntityMode (the entity-mode essentially defining which representation). If that given piece of data is thought of as a data structure, then a tuplizer is the thing which knows how to: create

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

NHibernate.Linq LIKE

耗尽温柔 提交于 2020-01-01 03:56:07
问题 How can I produce this query using NHibernate.Linq? WHERE this_.Name LIKE @p0; @p0 = 'test' // Notice NO % wild card Note, this is not Linq To Sql or Entity Framework. This is NHibernate. Edit: Here is the desired query using ICriteria: criteria.Add(Expression.Like("Name", "test")); return criteria.List<Theater>(); 回答1: With NH 4 (and probably a bit earlier), a built-in Like string extension is available within NHibernate.Linq namespace: Like(this string matchExpression, string sqlLikePattern

traversing object graph from n-tier client

[亡魂溺海] 提交于 2020-01-01 03:53:06
问题 I'm a student currently dabbling in a .Net n-tier app that uses Nhibernate+WCF+WPF. One of the things that is done quite terribly is object graph serialisation, In fact it isn't done at all, currently associations are ignored and we are using DTOs everywhere. As far as I can tell one method to proceed is to predefine which objects and collections should be loaded and serialised to go across the wire, thus being able to present some associations to the client, however this seems limited,