score:5
this was a bug in nhibernate. it would try to get the class mapping data for the enumerable type parameter. when projecting an enumerable of a mapped class this works perfectly. in this instance, however, the enumerable type parameter is string. string does not have a class map and so it was substituting a null constant in the query which then caused issues later on.
to further illustrate this, the sql query for this example would be:
select c.name, p.id, p.name from post p left join category c on p.id = c.postid where p.id = 1
this would return data like so:
c.name | p.id | p.name
--------------------------
cat 1 | 1 | post a
cat 2 | 1 | post a
nhibernate would then, in memory, perform a group by operation, including null checks, to create a list of categories for each unique value of p.id. the group by operation is performed using column indexes.
that is what should be happening. the bug was causing the results to be transformed, before the group by operation, into:
null | cat 1 | 1 | post a
null | cat 2 | 1 | post a
nhibernate was then filtering results where column 0 was null, meaning none of them survive.
the pull request containing the fix is here: https://github.com/nhibernate/nhibernate-core/pull/262
score:1
you can create categorymap
, category
entity and change to:
public virtual ilist<category> categories { get; protected set; }
i'm presuming is a linq to nhibernate querying limitation.
score:1
try changing
var second = session.query<post>()
.where(x => x.id == 1)
.select(x => new {
x.categories,
x.name,
})
.single();
to tolist().single()
instead of single()
.
i've seen this issue before, the problem is that the query will return multiple rows that are then coerced into a single anonymous type. the query fails because the intermediate results contain multiple rows instead of a single row.
Source: stackoverflow.com
Related Query
- NHibernate querying on a string collection using Linq results in either error or empty collection
- Collection to string using linq
- using LINQ how can i concatenate string properties from itesm in a collection
- Using LINQ to get the results from another LINQ collection
- Error When Querying For A Substring Using Dynamic Linq
- using Linq to break flat table results into object collection
- Querying a collection of collection using Linq
- Compiling Error with LINQ Sorting Code Using List<T>
- using LINQ to extract sections out of a string array into a new collection
- Converting string to nullable DayOfWeek field using Linq cause an error
- When querying a collection using linq it always returns a null
- How to join MongoDB collection with string[] on collection with string using Linq
- Replace all values in IQueryable with string based on results using LINQ
- When querying a collection using linq it always returns a null
- Error when using Contains within linq query with results from another query
- Convert a collection of objects with a string property to an enumeration of those strings using LINQ
- How to find an error in Linq using PropertyValidationErrors when key is not found in results
- Querying the database using EF Code First and Linq
- Create a string collection from CheckedListBox.CheckedItems using LINQ
- Querying Json as string within a property of an object using linq
- error in LINQ while converting IPaddress to String using C# and PostgreSQL database
- Error on querying element using LINQ to XML
- Update all objects in a collection using LINQ
- Convert string[] to int[] in one line of code using LINQ
- C# - code to order by a property using the property name as a string
- Using Linq to return a Comma separated string
- Convert string to int array using LINQ
- Check if a string has at least one number in it using LINQ
- Tradeoffs using NHibernate 3.0 QueryOver or LINQ provider
- How to remove duplicates from collection using IEqualityComparer, LinQ Distinct
More Query from same tag
- Best way for retrieving single record results in LINQ to SQL
- Why does Entity Framework 6 generate complex SQL queries for simple lookups?
- Getting a single object from SQL Server to a view
- Windows Form Controls and LINQ; What should I return?
- LINQ - Split results in months
- List<IEnumerator>.All(e => e.MoveNext()) doesn't move my enumerators on
- LINQ to Entities and creating a new instance of an entity
- Nullable entity projection in Entity Framework
- Select nested property values in LINQ
- How to access closed-over local variable in MemberExpression?
- LINQ version of SQL's LIKE statement
- C# algorithm - find least number of objects necessary
- Render html control while using with lambda expression
- How to get same results from select as foreach when using GroupBy()
- Compilation error when using expression in linq
- linq aggregate
- How do you force explicit tag closing with Linq XML?
- MVC 4 Retrieve db id from newly created entry
- Remove columns from datatable
- Giving wrong records when join statement used for two queries
- LINQ unexpected behavior when returning IEnumerable and calling ToArray
- How to do Linq aggregates when there might be an empty set?
- LINQ Join On Int = Char DataTypes?
- Is there a way to get the difference between two sets of objects in c#
- How to make f# query expressions reusable?
- Is it possible to change gridviewid to to a gridview DataSouce after the gridview is loaded
- Q: Sort a List of object by an inner List with Linq
- Pulling all rows from database then displaying them to a table
- Th linq query could not be translated. Either rewrite the query in a form that can be translated .NETCore
- How AsParallel extension actually works