nhibernate

Force query execution without flush/commit

自古美人都是妖i 提交于 2020-01-22 12:37:05
问题 Hi i am using the transaction-per-request (session-in-view) pattern for an asp.net web application. I have a couple of points in the application where i want to Save an NHibernate managed entity and then do a couple of more inserts and updates using common sql. These inserts/updates depend on the ID that the NH saved entity will take. The problem is that the generated id does not exist in the transactions' scope. If i force a flush/commit the id is persisted but if the inserts/updates fail i

NHibernate session is closed when refreshing page

↘锁芯ラ 提交于 2020-01-22 03:26:31
问题 This is another strange problem I've encountered this days!!! I've created and MVC 4 app using nhibernate. and added a filter attribute named [LoggingNHibernateSessionAttribute] on my HomeController which manages session for each action. I've followed 'ASP.NET MVC4 and the Web API published by Apress'. public class LoggingNHibernateSessionAttribute : ActionFilterAttribute { private readonly IActionLogHelper _actionLogHelper; private readonly IActionExceptionHandler _actionExceptionHandler;

Return entity via projection query

扶醉桌前 提交于 2020-01-21 05:29:07
问题 Is it possible to return an entity using a projection query? I've successfully done it with a SQL query (see below), but can't find how to do it with a projection query. Dim sql As String = "SELECT {a.*}, {b.*} FROM a LEFT OUTER JOIN b ON a.pk = b.fk") ' Convert SQL results into entities {a} and {b} Dim query As IQuery = session.CreateSQLQuery(sql) _ .AddEntity("a", GetType(a)) _ .AddEntity("b", GetType(b)) Return query.List() 回答1: Yes, you can return entities from projection queries. If you

Attaching a disconnected object to an NHibernate session; best practice?

和自甴很熟 提交于 2020-01-21 02:46:55
问题 My repository works in a UnitOfWork model; all operations, whether retrieval or persistence, must be performed within the scope of an IDisposable UnitOfWork token object, which behind the scenes is associated with a Session that performs the work requested. So, the basic pattern is: using (var uow = repo.BeginUnitOfWork()) { try { //DB operations here; all repo methods require passing in uow. ... repo.CommitUnitOfWork(uow); } catch(Exception) { repo.RollbackUnitOfWork(uow); throw; } } I've

How to configure fluent nHibernate with MySQL

时光怂恿深爱的人放手 提交于 2020-01-20 17:08:27
问题 I'm trying to configure nHibernate to use a MySql database. I found examples for mssql and sqlite but none for mysql. So, how do I change this so it uses mysql: Fluently.Configure().Database( MsSqlConfiguration.MsSql2005.ConnectionString( c => c.FromConnectionStringWithKey("ConnectionString") ) ) .Mappings(m => m.FluentMappings.AddFromAssemblyOf<MyAutofacModule>()) .BuildSessionFactory()) 回答1: Change MsSqlConfiguration.MsSql2005 , to MySqlConfiguration.Standard , it was the one thing I

No Persister for: error on save with INotifyPropertyChanged Interceptor

眉间皱痕 提交于 2020-01-17 08:22:16
问题 Using the method described in NHibernate & INotifyPropertyChanged, the repository will return a collection of proxies that implement INotifyPropertyChanged, but on some objects when saving or deleting it will throw an error: at NHibernate.Impl.SessionFactoryImpl.GetEntityPersister(String entityName) at NHibernate.Impl.SessionImpl.GetEntityPersister(String entityName, Object obj) at NHibernate.Engine.ForeignKeys.IsTransient(String entityName, Object entity, Nullable`1 assumed,

How can I run multiple inserts with NHibernate in one go?

纵饮孤独 提交于 2020-01-17 06:00:12
问题 I am trying to find the most efficient way of running multiple (> 1000) insert statements with NHibernate. The actual insert statement is very simple as it uses an FK ID from a newly created object together with values from a subquery. Here's what I would write in SQL: insert into dbo.NotificationView select 1 AS IDOfNewItem, U.Id AS UserID, 0 AS HasEdited from [User] U INNER JOIN UserSite US ON U.Id = US.UserId where US.SiteId = 1 I have seen that there is the parameter called adonet.batch

Spring.NET + NHibernate - Multiple (Distinct) Databases with OpenSessionInView

て烟熏妆下的殇ゞ 提交于 2020-01-17 03:45:08
问题 In my web application, I have 2 totally different databases - one that's being used mostly by a CMS from which we'd like to get page information on non CMS pages on the same website, & one that contains totally different data. Is it possible to use Spring.NET's Open Session In View module with multiple session factories for both of those databases, so in this case I have 2 objects defined in spring.config of type Spring.Data.NHibernate.LocalSessionFactoryObject ? 回答1: I think you are talking

could not get a field value by reflection getter… nhibernate query cache with 2nd level cache

不问归期 提交于 2020-01-17 03:16:08
问题 I got this exception could not get a field value by reflection getter of DictionaryMaster. k__BackingField with this inner exception: Field '<>k__BackingField' defined on type is not a field on the target object which is of type 'System.Object[]'. The problem exists only when i use eagerloading in query. Below i put my classes, relations and query. public class DictionaryMaster { public virtual IList<DictionaryItem> DictionaryItems { get; private set; } public virtual System.String Code { get

Many-to-one relation exception due to closed session after loading

纵饮孤独 提交于 2020-01-16 17:38:29
问题 I am using NHibernate (version 1.2.1) for the first time so I wrote a simple test application (an ASP.NET project) that uses it. In my database I have two tables: Persons and Categories. Each person gets one category, seems easy enough. | Persons | | Categories | |--------------| |--------------| | Id (PK) | | Id (PK) | | Firstname | | CategoryName | | Lastname | | CreatedTime | | CategoryId | | UpdatedTime | | CreatedTime | | Deleted | | UpdatedTime | | Deleted | The Id, CreatedTime,