{"action":"created","issue":{"url":"https://api.github.com/repos/nhibernate/nhibernate-core/issues/948","repository_url":"https://api.github.com/repos/nhibernate/nhibernate-core","labels_url":"https://api.github.com/repos/nhibernate/nhibernate-core/issues/948/labels{/name}","comments_url":"https://api.github.com/repos/nhibernate/nhibernate-core/issues/948/comments","events_url":"https://api.github.com/repos/nhibernate/nhibernate-core/issues/948/events","html_url":"https://github.com/nhibernate/nhibernate-core/issues/948","id":264953682,"number":948,"title":"NH-3435 - Ability to select entities in Criteria projections","user":{"login":"nhibernate-bot","id":20959043,"avatar_url":"https://avatars3.githubusercontent.com/u/20959043?v=4","gravatar_id":"","url":"https://api.github.com/users/nhibernate-bot","html_url":"https://github.com/nhibernate-bot","followers_url":"https://api.github.com/users/nhibernate-bot/followers","following_url":"https://api.github.com/users/nhibernate-bot/following{/other_user}","gists_url":"https://api.github.com/users/nhibernate-bot/gists{/gist_id}","starred_url":"https://api.github.com/users/nhibernate-bot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nhibernate-bot/subscriptions","organizations_url":"https://api.github.com/users/nhibernate-bot/orgs","repos_url":"https://api.github.com/users/nhibernate-bot/repos","events_url":"https://api.github.com/users/nhibernate-bot/events{/privacy}","received_events_url":"https://api.github.com/users/nhibernate-bot/received_events","type":"User","site_admin":false},"labels":[{"id":717851256,"url":"https://api.github.com/repos/nhibernate/nhibernate-core/labels/c:%20Core","name":"c: Core","color":"ededed","default":false},{"id":718400270,"url":"https://api.github.com/repos/nhibernate/nhibernate-core/labels/migrated","name":"migrated","color":"ededed","default":false},{"id":717863290,"url":"https://api.github.com/repos/nhibernate/nhibernate-core/labels/p:%20Minor","name":"p: Minor","color":"f9d0c4","default":false},{"id":661450474,"url":"https://api.github.com/repos/nhibernate/nhibernate-core/labels/r:%20Fixed","name":"r: Fixed","color":"0e8a16","default":false},{"id":661468620,"url":"https://api.github.com/repos/nhibernate/nhibernate-core/labels/t:%20New%20Feature","name":"t: New Feature","color":"c2e0c6","default":false}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":{"url":"https://api.github.com/repos/nhibernate/nhibernate-core/milestones/9","html_url":"https://github.com/nhibernate/nhibernate-core/milestone/9","labels_url":"https://api.github.com/repos/nhibernate/nhibernate-core/milestones/9/labels","id":2679958,"number":9,"title":"5.1","description":"","creator":{"login":"hazzik","id":144791,"avatar_url":"https://avatars1.githubusercontent.com/u/144791?v=4","gravatar_id":"","url":"https://api.github.com/users/hazzik","html_url":"https://github.com/hazzik","followers_url":"https://api.github.com/users/hazzik/followers","following_url":"https://api.github.com/users/hazzik/following{/other_user}","gists_url":"https://api.github.com/users/hazzik/gists{/gist_id}","starred_url":"https://api.github.com/users/hazzik/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hazzik/subscriptions","organizations_url":"https://api.github.com/users/hazzik/orgs","repos_url":"https://api.github.com/users/hazzik/repos","events_url":"https://api.github.com/users/hazzik/events{/privacy}","received_events_url":"https://api.github.com/users/hazzik/received_events","type":"User","site_admin":false},"open_issues":8,"closed_issues":136,"state":"open","created_at":"2017-08-03T22:42:55Z","updated_at":"2018-03-10T20:23:31Z","due_on":"2017-12-15T08:00:00Z","closed_at":null},"comments":0,"created_at":"2017-10-12T14:01:37Z","updated_at":"2018-03-11T19:36:49Z","closed_at":"2017-12-23T12:51:51Z","author_association":"COLLABORATOR","body":"**Jonathan Hynes** created an [issue](https://nhibernate.jira.com/browse/NH-3435) — <time datetime=\"2013-04-01T13:44:03.748Z\" title=\"2013-04-01T13:44:03.748Z\">1st April 2013, 13:44:03</time>:\r\n> The Criteria API need a way to select an Entity as a projection. Suggest the following methods:\r\n> ```c#\r\n> Projection.RootEntity()\r\n> Projection.Entity(string associationPath)\r\n> ```\r\n> This issue may be a duplicate of one of the following, but these issues have been closed and the problem is not resolved:\r\n> [NH-1372](https://nhibernate.jira.com/browse/NH-1372)\r\n> [NH-928](https://nhibernate.jira.com/browse/NH-928)\r\n> \r\n> Background to the issue can be found here:\r\n> http://stackoverflow.com/questions/15744057/nhibernate-how-to-select-the-root-entity-in-a-projection\r\n> \r\n---\r\n**Ricardo Peres** added a comment — <time datetime=\"2014-03-06T20:46:57.344Z\" title=\"2014-03-06T20:46:57.344Z\">6th March 2014, 20:46:57</time>:\r\n> I implemented a solution: http://weblogs.asp.net/ricardoperes/archive/2014/03/06/custom-nhibernate-criteria-projections.aspx.\r\n> If anyone can confirm that it works, I may submit a pull request.\r\n> \r\n---\r\n**Jonathan Hynes** added a comment — <time datetime=\"2014-03-14T22:42:07.238Z\" title=\"2014-03-14T22:42:07.238Z\">14th March 2014, 22:42:07</time>:\r\n> I tested using the `MsSql2008Dialect`. This does not appear to work because aliases are the property name and are not escaped/quoted. This can cause issues if keywords are used as column names. This could also cause problems if multiple projections have the same property name.\r\n> \r\n---\r\n**Ricardo Peres** added a comment — <time datetime=\"2014-03-14T22:56:53.768Z\" title=\"2014-03-14T22:56:53.768Z\">14th March 2014, 22:56:53</time>:\r\n> What does \"does not appear to work\" mean? Does it return, in normal cases, what it should, or does it not?\r\n> Not using aliases was a deliberate option, so that we can use `AliasToBean` in order to generate entities from the projection. Quoting is easy to do.\r\n> Anyway, this was a proof of concept, I even made chances to the sample after I published that post. If I ever submit a pull request, I will address some of this issues.\r\n> \r\n---\r\n**Jonathan Hynes** added a comment — <time datetime=\"2014-03-14T23:11:03.263Z\" title=\"2014-03-14T23:11:03.263Z\">14th March 2014, 23:11:03</time>:\r\n> My test is as follows:\r\n> ```c#\r\n> //Code to persist 20 Person objects here\r\n> \r\n> var list = Session.CreateCriteria<Person>()\r\n>               .SetFirstResult(5)\r\n>               .SetMaxResults(10)\r\n>               .SetProjection(new RootEntityProjection(), Projections.SqlFunction(\"rowcount\", NHibernateUtil.Int64))\r\n>               .List<object[]>();\r\n> \r\n> Assert.Equal(10, list.Count);\r\n>             Assert.Equal(20, (long)list<0>[1]);\r\n>             Assert.IsType<Person>(list<0>[0]);\r\n> ```\r\n> The `Person` class has a `User` property. Since `User` is a SQL server keyword, I am getting the following error:\r\n> ```\r\n> System.Data.SqlClient.SqlException : Incorrect syntax near the keyword 'User'.\r\n> ```\r\n> Looking at the generated SQL, given the lack of uniquifying aliases, I also make the conjecture that the generated SQL could have alias conflicts. For instance, suppose `Person` had the following property:\r\n> ```c#\r\n> public virtual Person Father{get;set;}\r\n> ```\r\n> And I modified the query to say:\r\n> ```c#\r\n> .CreateAlias(\"Father\", \"f\")\r\n> .SetProjection(new RootEntityProjection(), new EntityProjection(Person, \"f\"))\r\n> ```\r\n> I conjecture that this would create duplicate aliases in the generated SQL for every property in the `Person` class.\r\n> \r\n---\r\n**Ricardo Peres** added a comment — <time datetime=\"2014-03-14T23:18:08.259Z\" title=\"2014-03-14T23:18:08.259Z\">14th March 2014, 23:18:08</time>:\r\n> The problem with having aliases is that we cannot turn the results into entities. Anyway, I will post a new version that addresses your concerns.\r\n> \r\n---\r\n**Ricardo Peres** added a comment — <time datetime=\"2014-03-15T11:22:15.114Z\" title=\"2014-03-15T11:22:15.114Z\">15th March 2014, 11:22:15</time>:\r\n> Jonathan, thanks for your feedback! Can I please ask you to try this new version?\r\n> \r\n> \r\n---\r\n**Jonathan Hynes** added a comment — <time datetime=\"2014-03-15T12:07:05.013Z\" title=\"2014-03-15T12:07:05.013Z\">15th March 2014, 12:07:05</time>:\r\n> Now I am getting this error:\r\n> ```\r\n> System.ArgumentOutOfRangeException : Index was out of range. Must be non-negative and less than the size of the collection.\r\n> Parameter name: index\r\n> Result StackTrace:\t\r\n> at System.ThrowHelper.ThrowArgumentOutOfRangeException()\r\n>    at System.SZArrayHelper.get_Item<T>(Int32 index)\r\n>    at System.Linq.Enumerable.ElementAt<TSource>(IEnumerable`1 source, Int32 index)\r\n>    at NHibernate.Criterion.BaseProjection.NHibernate.Criterion.IProjection.ToSqlString(ICriteria criteria, Int32 position, ICriteriaQuery criteriaQuery, IDictionary`2 enabledFilters) in d:\\dev\\npf\\Drg.M3\\Dao\\Base\\BaseProjection.cs:line 131\r\n>    at NHibernate.Criterion.ProjectionList.ToSqlString(ICriteria criteria, Int32 loc, ICriteriaQuery criteriaQuery, IDictionary`2 enabledFilters)\r\n>    at NHibernate.Loader.Criteria.CriteriaQueryTranslator.GetSelect(IDictionary`2 enabledFilters)\r\n>    at NHibernate.Loader.Criteria.CriteriaJoinWalker..ctor(IOuterJoinLoadable persister, CriteriaQueryTranslator translator, ISessionFactoryImplementor factory, ICriteria criteria, String rootEntityName, IDictionary`2 enabledFilters)\r\n>    at NHibernate.Loader.Criteria.CriteriaLoader..ctor(IOuterJoinLoadable persister, ISessionFactoryImplementor factory, CriteriaImpl rootCriteria, String rootEntityName, IDictionary`2 enabledFilters)\r\n>    at NHibernate.Impl.SessionImpl.List(CriteriaImpl criteria, IList results)\r\n>    at NHibernate.Impl.CriteriaImpl.List(IList results)\r\n>    at NHibernate.Impl.CriteriaImpl.List<T>()\r\n>    at Drg.M3.Tests.Unit.Core.NHibernateFacts.RootEntityProjectionWorks() in d:\\dev\\npf\\Drg.M3.Tests.Unit\\Core\\NHibernateFacts.cs:line 26\r\n> ```\r\n> FYI, my persister is a `JoinedSubclassEntityPersister`. It's getting this error on the first property and first column name (i==0, c==0), and the property in question is a one-to-one.\r\n> \r\n---\r\n**Ricardo Peres** added a comment — <time datetime=\"2014-08-13T14:31:12.201Z\" title=\"2014-08-13T14:31:12.201Z\">13th August 2014, 14:31:12</time>:\r\n> Pull request: https://github.com/nhibernate/nhibernate-core/pull/299\r\n> \r\n---\r\n**Ricardo Peres** added a comment — <time datetime=\"2014-08-14T10:22:41.085Z\" title=\"2014-08-14T10:22:41.085Z\">14th August 2014, 10:22:41</time>:\r\n> New pull request: https://github.com/nhibernate/nhibernate-core/pull/302\r\n> \r\n---\r\n**Ricardo Peres** added a comment — <time datetime=\"2014-10-10T13:26:18.398Z\" title=\"2014-10-10T13:26:18.398Z\">10th October 2014, 13:26:18</time>:\r\n> Fix version? Maybe 4.1?\r\n> \r\n---\r\n**Alexander Zaytsev** added a comment — <time datetime=\"2016-08-12T04:40:11.455Z\" title=\"2016-08-12T04:40:11.455Z\">12th August 2016, 4:40:11</time>:\r\n> Move unresolved improvements and new features with minor and trivial priorities to 4.2.0\r\n> \r\n---\r\n**Alexander Zaytsev** added a comment — <time datetime=\"2017-09-14T01:47:17.339Z\" title=\"2017-09-14T01:47:17.339Z\">14th September 2017, 1:47:17</time>:\r\n> Move issues from 4.2 to 5.0\r\n> \r\n---\r\n**Alexander Zaytsev** added a comment — <time datetime=\"2017-09-14T01:50:03.693Z\" title=\"2017-09-14T01:50:03.693Z\">14th September 2017, 1:50:03</time>:\r\n> Move new features to 5.1\r\n> "},"comment":{"url":"https://api.github.com/repos/nhibernate/nhibernate-core/issues/comments/372142517","html_url":"https://github.com/nhibernate/nhibernate-core/issues/948#issuecomment-372142517","issue_url":"https://api.github.com/repos/nhibernate/nhibernate-core/issues/948","id":372142517,"user":{"login":"fredericDelaporte","id":12201973,"avatar_url":"https://avatars2.githubusercontent.com/u/12201973?v=4","gravatar_id":"","url":"https://api.github.com/users/fredericDelaporte","html_url":"https://github.com/fredericDelaporte","followers_url":"https://api.github.com/users/fredericDelaporte/followers","following_url":"https://api.github.com/users/fredericDelaporte/following{/other_user}","gists_url":"https://api.github.com/users/fredericDelaporte/gists{/gist_id}","starred_url":"https://api.github.com/users/fredericDelaporte/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fredericDelaporte/subscriptions","organizations_url":"https://api.github.com/users/fredericDelaporte/orgs","repos_url":"https://api.github.com/users/fredericDelaporte/repos","events_url":"https://api.github.com/users/fredericDelaporte/events{/privacy}","received_events_url":"https://api.github.com/users/fredericDelaporte/received_events","type":"User","site_admin":false},"created_at":"2018-03-11T19:36:49Z","updated_at":"2018-03-11T19:36:49Z","author_association":"OWNER","body":"@bahusoid quote:\r\n\r\n> I think this issue needs to be renamed to \"Ability to select entities in a criteria projection\" . As implementation #1471 is not limited to root entity.\r\n\r\nDone."}}
{"actor":{"display_login":"fredericDelaporte"}}