nhibernate

Parameter index is out of range

落花浮王杯 提交于 2020-02-03 04:15:08
问题 I am getting the following error when trying to update an object using nhibernate. I am attempting to update a field which is a foreign key. Any thoughts why I might be getting this error? I can't figure it out from that error and my log4net log doesn't give any hints either. Thanks System.IndexOutOfRangeException was unhandled by user code Message="Parameter index is out of range." Source="MySql.Data" StackTrace: at MySql.Data.MySqlClient.MySqlParameterCollection.CheckIndex(Int32 index) at

NHibernate Validator: Using Attributes vs. Using ValidationDefs

时光怂恿深爱的人放手 提交于 2020-01-31 18:42:47
问题 I've been using NH Validator for some time, mostly through ValidationDef s, but I'm still not sure about two things: Is there any special benefit of using ValidationDef for simple/standard validations (like NotNull , MaxLength etc)? I'm worried about the fact that those two methods throw different kinds of exceptions on validation, for example: ValidationDef 's Define.NotNullable() throws PropertyValueException When using [NotNull] attribute, an InvalidStateException is thrown. This makes me

NHibernate : Query by example on primary key produces “WHERE (1=1)”

眉间皱痕 提交于 2020-01-31 18:04:09
问题 I have an entity Customer public class Customer { public virtual int ID { get; set; } public virtual string Firstname { get; set; } public virtual string Lastname { get; set; } } and my DAL method is : public IList<Customer> GetCustomers(Customer example) { var customers = default(IList<Customer>); using (var sessiong = GetSession()) { customers = sessiong.CreateCriteria(typeof(Customer)) .Add(Example.Create(example)) .List<Customer>(); } return customers; } but the problem is that when I

NHibernate : Query by example on primary key produces “WHERE (1=1)”

帅比萌擦擦* 提交于 2020-01-31 18:00:52
问题 I have an entity Customer public class Customer { public virtual int ID { get; set; } public virtual string Firstname { get; set; } public virtual string Lastname { get; set; } } and my DAL method is : public IList<Customer> GetCustomers(Customer example) { var customers = default(IList<Customer>); using (var sessiong = GetSession()) { customers = sessiong.CreateCriteria(typeof(Customer)) .Add(Example.Create(example)) .List<Customer>(); } return customers; } but the problem is that when I

NHibernate : Query by example on primary key produces “WHERE (1=1)”

时光怂恿深爱的人放手 提交于 2020-01-31 18:00:47
问题 I have an entity Customer public class Customer { public virtual int ID { get; set; } public virtual string Firstname { get; set; } public virtual string Lastname { get; set; } } and my DAL method is : public IList<Customer> GetCustomers(Customer example) { var customers = default(IList<Customer>); using (var sessiong = GetSession()) { customers = sessiong.CreateCriteria(typeof(Customer)) .Add(Example.Create(example)) .List<Customer>(); } return customers; } but the problem is that when I

How to query the first entry in each group in NHibernate

无人久伴 提交于 2020-01-30 04:38:21
问题 The following code using LINQ in NHibernate returns a different result from in-memory LINQ and EF LINQ. What is the correct way to do this in NHibernate? It is fine to use QueryOver if the LINQ version is indeed broken. using (var session = factory.OpenSession()) using (var transaction = session.BeginTransaction()) { for (int i = 0; i < 10; ++i) { session.Save(new A() { X = i % 2, Y = i / 2, }); } transaction.Commit(); } using (var session = factory.OpenSession()) using (var transaction =

Calling List<T>.Clear() causing IndexOutOfRangeException

强颜欢笑 提交于 2020-01-30 04:28:12
问题 I have a List<T> that is in an entity class that is being populated via NHibernate. When I call .Clear() on that list, I am getting an IndexOutOfRangeException . I've verified that that list has items in in before this is called, but the same exception is thrown. Under what circumstances would you expect to get this exception when you call this method? private readonly List<VacancyTag> _vacancyTags = new List<VacancyTag>(); public virtual void RemoveAllVacancyTags() { _vacancyTags.Clear(); }

Using SQL Server 2008 Geography types with nHibernate's CreateSQLQuery

为君一笑 提交于 2020-01-29 04:12:06
问题 I am trying to issue a SQL update statement with nHibernate (2.0.1GA) like this: sqlstring = string.Format("set nocount on;update myusers set geo=geography::Point({0}, {1}, 4326) where userid={2};", mlat, mlong, userid); _session.CreateSQLQuery(sqlstring).ExecuteUpdate(); However I receive the following error: 'geography@p0' is not a recognized built-in function name. I thought CreateSQLQuery would just pass the SQL I gave it and execute it...guess not. Any ideas on how I can do that within

Generate table indexes using Fluent NHibernate

血红的双手。 提交于 2020-01-28 17:59:44
问题 Is it possible to generate table indexes along with the rest of the database schema with Fluent NHibernate? I would like to be able to generate the complete database DDL via an automated build process. 回答1: In more recent versions of Fluent NHibernate, you can call the Index() method to do this rather than using SetAttribute (which no longer exists): Map(x => x.Prop1).Index("idx__Prop1"); 回答2: Do you mean indexes on columns? You can do it manually in your ClassMap<...> files by appending

How to turn off NHibernate's automatic (dirty checking) update behaviour?

点点圈 提交于 2020-01-28 04:41:11
问题 I've just discovered that if I get an object from an NHibernate session and change a property on object, NHibernate will automatically update the object on commit without me calling Session.Update(myObj) ! I can see how this could be helpful, but as default behaviour it seems crazy! Update: I now understand persistence ignorance, so this behaviour is now clearly the preferred option. I'll leave this now embarrassing question here to hopefully help other profane users. How can I stop this