nhibernate

Unable to cast object of type 'NHibernate.Hql.Ast.HqlCast' to type 'NHibernate.Hql.Ast.HqlBooleanExpression

拈花ヽ惹草 提交于 2019-12-23 11:46:25
问题 I'm using the following c# code: public IList<T> GetAllByExpression(Expression<Func<T, bool>> expression, int startIndex, int count, Func<T, DateTime> dateTimeSelector) { using (ISession session = NHibernateHelper.GetSession()) { return session.Query<T>() .Where(expression) .OrderBy(dateTimeSelector) .Skip(startIndex - 1) .Take(count) .ToList(); } } update: even the follwoing code throws the same exception: public IList<T> GetAllByExpression(Expression<Func<T, bool>> expression, int

nhibernate could not resolve property (Only in Visual Studio 2015) with a LeftOuterJoin

人盡茶涼 提交于 2019-12-23 10:34:47
问题 I need some help as can't really explain this one. We have a semi complex nhibernate query: var query = _tyreRepository.Session.QueryOver<Tyre>(() => tyreAlias) .JoinQueryOver<Pattern>(() => tyreAlias.Pattern, () => patternAlias) .JoinQueryOver<Brand>(() => patternAlias.Brand, () => brandAlias) .JoinQueryOver<RimSize>(() => tyreAlias.RimSize, () => rimSizeAlias) .JoinQueryOver(() => tyreAlias.SpeedIndex, () => speedIndexAlias, JoinType.LeftOuterJoin); Which works fine in Visual Studio 2012,

How to return id from NHibernate ISession.SaveOrUpdate

纵然是瞬间 提交于 2019-12-23 10:27:34
问题 I am using ISession.SaveOrUpdate to insert new objects and updaet existing. If I use ISession.Save(..) this returns the identity of the inserted record. For SaveOrUpdate I am doing the following: public int Save(Vehicle entity) { using (var txn = _session.BeginTransaction()) { _session.SaveOrUpdate(entity); txn.Commit(); } return entity.Id; } Is this the best way to return my identity? Thanks, Ben 回答1: There's nothing wrong with that. But since the identity is set on the object, why not make

Fluent NHibernate - IndexOutOfRange

…衆ロ難τιáo~ 提交于 2019-12-23 10:01:23
问题 I've read all the posts and know that IndexOutOfRange usually happens because a column is being referenced twice. But I don't see how that's happening based on my mappings. With SHOW_SQL true in the config, I see an Insert into the Events table and then an IndexOutOfRangeException that refers to the RadioButtonQuestions table. I can't see the SQL it's trying to use that generates the exception. I tried using AutoMapping and have now switched to full ClassMap for these two classes to try to

Fluent nHibernate Join is doing insert into joined table

℡╲_俬逩灬. 提交于 2019-12-23 09:51:08
问题 I am trying to use join to pull in a single property from another table, which doesn't have a mapping. My problem is that when I create a new instance of my mapped entity and save it I get an error about trying to insert into my unmapped table (it's trying to insert null into a not null column). I thought using .ReadOnly() would stop nhibernate from trying to insert into my unmapped table but that doesn't seem to work. My mapping looks like this: // Join _UnMapped table with Mapped table to

The factory was disposed and can no longer be used. NHibernatefacility

霸气de小男生 提交于 2019-12-23 09:36:30
问题 I have been trying for three days to figure out this NHibernatefacility thing with Castle and wcf and it's really getting frustrating. After solving a good dozen of errors, i have come to this one which seems pretty obvious but i can't solve. This is my global.asax's Application_Start container.AddFacility<AutoTxFacility>(); container.Register(Component.For<INHibernateInstaller>().ImplementedBy<NHibernateInstaller>()); container.AddFacility<NHibernateFacility>(); container.AddFacility

GroupBy SqlFunction on QueryOver

丶灬走出姿态 提交于 2019-12-23 09:33:18
问题 I have a list of all distinct account name prefixes (a-z) which I acquire using var accounts = this.SessionManager.GetActiveSession().QueryOver<Account>(); var q = accounts.Select(Projections.Distinct( Projections.SqlFunction("substring", NHibernateUtil.String, Projections.Property("Name"), Projections.Constant(1), Projections.Constant(1)))); However what I want to do is instead of returning a distinct list is group the prefixes and return the number of accounts that start with that prefix,

Fluent NHibernate mapping nullable enum

时光总嘲笑我的痴心妄想 提交于 2019-12-23 09:33:06
问题 I need to map a nullable enum in my class but am getting exceptions. NHibernate.PropertyAccessException: Invalid Cast (check your mapping for property type mismatches); setter of App.Model.Stock ---> System.InvalidCastException: Specified cast is not valid. I have narrowed the issue down to one specific property, which I describe below. This was previously answered here, but the solution links to a page which no longer exists. Here is my code, which I have reduced to contain only the portions

Session is closed Object name: 'ISession'. at NHibernate.Impl.AbstractSessionImpl.ErrorIfClosed() - How to stop the session from closing prematurely

一世执手 提交于 2019-12-23 09:32:41
问题 I am using NHibernate in an MVC C# application with MySQL. I am trying to have multiple users access the session. I have been using .InRequestScope() on my session but i am still getting: System.ObjectDisposedException: Session is closed! Object name: 'ISession'. at NHibernate.Impl.AbstractSessionImpl.ErrorIfClosed() * ...or DataReader errors when i have my colleagues all navigate to the same page that accesses a Service at the same time. My IMasterSessionSource injection Bind

How I can tell NHibernate to save only changed properties

你。 提交于 2019-12-23 09:30:09
问题 I have class Person mapped to database with NHibernate. I load objects from DB and send it to different clients. First client will modify Name and Country property. Second client will modify only Name property. Then both returns modified objects to server. When I save data from first client - then saved correctly, both - name and country updated. When I save data from second client - I have problem. It was override data from first client and save new name and initial value of country. How I