Error Performing Loadbyuniquekey Sql Sql Not Available Nhibernate
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up NHibernate: Composite key, one-to-one relation and “Error performing LoadByUniqueKey” up vote 0 down vote favorite I have two classes. Class 1: public class Einsatz { public virtual ProjNrPindex Id { get; set; } public virtual Int32? Knr { get; set; } public virtual String RessNr { get; set; } public virtual String AdrNr { get; set; } public virtual DateTime EndeIst { get; set; } public virtual DateTime StartIst { get; set; } public virtual DateTime ArbeitsbeginnIst { get; set; } public virtual String Kennwort { get; set; } public virtual Taetigkeit Taetigkeit { get; set; } public Einsatz() { this.Id = new ProjNrPindex(); } public class ProjNrPindex { public virtual Int32? Pindex { get; set; } public virtual String ProjNr { get; set; } public override Boolean Equals(Object obj) { if (obj as Einsatz == null) { return(false); } if (Object.ReferenceEquals(this, obj) == true) { return(true); } ProjNrPindex other = obj as ProjNrPindex; if (Object.Equals(this.Pindex, other.Pindex) == false) { return(false); } if (Object.Equals(this.ProjNr, other.ProjNr) == false) { return(false); } return(true); } public override Int32 GetHashCode() { Int32 hash = 0; hash += (this.Pindex != null) ? this.Pindex.GetHashCode() : 0; hash += 1000 * ((this.ProjNr != null) ? this.ProjNr.GetHashCode() : 0); return(hash); } } public override bool Equals(object obj) { var other = obj as Einsatz; if (ReferenceEquals(null, other)) return false; if (ReferenceEquals(this, other)) return true; return this.Id.Equals(other.Id); } public override int GetHashCode() { unchecked { int hash = GetType().GetHashCode(); hash = (hash * 31) ^ this.Id.GetHashCode(); return hash; } } } Class 2: public cla
of 1 [ 1 post ] Previous topic | Next topic Author Message moorcroft Post subject: The given key was not present in the dictionary.Posted: Tue Dec 01, 2009 7:48 am Newbie Joined: Tue http://stackoverflow.com/questions/13686822/nhibernate-composite-key-one-to-one-relation-and-error-performing-loadbyuniqu Jul 28, 2009 8:28 amPosts: 18 Hi I'm looking some help in doing some EntityTests. Basically when I run the code:Code:ISession session = sessionFactory.OpenSession();ICriteria criteria = session.CreateCriteria(typeof (Application));IList
SQL not available] in C# NHibernate could not execute query[SQL: SQL not available] in C# I was writing some new code that would use NHibernate a few days back and while I was testing it http://www.thebestcsharpprogrammerintheworld.com/blogs/NHibernate-could-not-execute-query-SQL-SQL-not-available.aspx I received thie error: Could not execute query[SQL: SQL not available] The value xxx is not of type xxx.xxx.xxx and cannot be used in this generic collection. Parameter name: value de-DE: xxx ist kein Wert des Typs xxx und kann in dieser generischen Auflistung nicht verwendet werden. Parametername: value I received this error while running this code: IQuery query = session.CreateQuery("select id from company"); IList<company> list = query.List<company>(); int count = list.Count; It failed on error performing line 2 where I called the List method on the query. The IQuery object looked like the below image. Notice that the ReturnAliases is a string and the ReturnTypes is an int. In my case, the id in the above HQL query is an int. I believe it is failing becuase of the attempted conversion from int to string. When I changed the code to look like the below, the code executed as expected. SImply becuase error performing loadbyuniquekey we let the compiler make the decision on the varialbe type by using the var type. var query = session.CreateQuery("select id from company") .List(); int count = query.Count; As well, this code segment executed as expected: IQuery query = session.CreateQuery("from company"); IList<company> list = query.List<company>(); In this case, the IQuery objects' ReturnAlias was null and the ReturnTypes contained an instance of my class. The point here is that if you want to select only a subset of your class (projection) using HQL, then you need to capture the results in a var variable. Feedback / Question Your Name:Your Email: Subject: Feedback/Question: A comment is required. Special or > 300 characters are not allowed. I had to remove the capability to leave feedback due to this. Will be back soon. page.Translate() Translate this pagePowered by Microsoft® Translator blog.Stats() Posts: 123 Comments: 87 Fundamentals: 16 my.Publications() me.About() blog.Archive() 2014 September (11) 2014 February (5) 2014 January (5) 2013 December (2) 2013 November (2) 2012 December (2) 2012 November (2) 2012 October (2) 2012 September (2) 2012 August (1) 2012 July (3) 2012 June (2) 2012 May (4) 2012 April (5) 2012 March (4) 2012 February (4) 2012 January (5) 2011 December (2) 2011 November (6) 2011 October (7) 2011 September (7) 201