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
- Executing raw sql in entity framework does not return result set
- using a group by in linq to select aggregated records
- Only select certain items from related table using linq
- C# / Unity / Linq - How to check if a list of lists contains a specific another list?
- Translate SQL statement with inner joins to LINQ
- Joining data that exists in two tables and aggregating non joined data
- Convert Sum(case) SQL statement to LINQ query in Entity Framework
- Prioritizing fields when matching multiple fields with linq
- How can i do this calculation in c#
- C# LINQ: Efficient way to set anonymous type property based on other values in query?
- How to change multiple attribute values from collection of elements?
- how to could use reflection to write to the appropriate properties on the entity?
- How to do IF when creating JSON with LINQ?
- EF linq statement not generating nested select count(*)
- How to make html table from sql linq in C#?
- how to get data from datatable by ( select and Group By)
- add all values to a list of list from a list
- Using SQL-distinct function in LINQ
- first issue with first linq
- Can I use LINQ without Entity Framework?
- Howto add a subset of a List to a property of an object in another List - best/fastest practice
- Extracting Week number from DateTime value in Linq to entity query
- Dynamic LINQ statement
- SQL to LINQ duplicated group count
- Efficiently make iterative LINQ to SQL queries
- select decimal value through LINQ
- Context Disposed Error before DropDownListFor() get populated
- Linq query results in the same references when initializing a variable
- Create Lambda Expression Selector For New Class Using Expression Tree
- Error while creating XML file