The same exception can be reproduce with next test: public class SelectionTests : LinqTestCase { ...... [Test] public void CanDoProjectionWithCast() { var lst1 = db.Users.Select(p => new { p1 = p.Name }).ToList();
Assert.AreEqual(3, lst1.Count());
var lst2 = db.Users.Select(p => new { p1 = (p as User).Name }).ToList();
We were waiting 3.3.2 so much to solve this issue and work with WCF Data Services, but the issue still appears. We missed one small point in the unit test: paging. We use paging and here the resulting URI: http://localhost:5555/odata/Securities()?$top=100&$select=Name which is logically the same as:
securities .OrderBy(s => s.SecurityID) .Take(100) .Select(s => new { (s as Security).Name }) .ToArray();
So our unit test should be modified to:
[Test] public void CanProjectWithCast() { // // ReSharper disable RedundantCast
var names1 = db.Users.OrderBy(p => p.Id).Take(10).Select(p => new { p1 = p.Name }).ToList(); Assert.AreEqual(3, names1.Count);
... }
As I am unable to reopen this bug, I will open another and submit pull ticket with new unit test.
Oskar Berggren
October 21, 2012 at 11:04 AM
Backported to 3.3.x branch circa 678845d3fcc127d2f337e89890a7ce595a1a4d55.
Alex Zaytsev
September 27, 2012 at 7:00 PM
Better fix commited to master 64ae059fb4c30fd4f19a3370576b237bcf4b5f0d
Alex Zaytsev
September 18, 2012 at 1:19 PM
Fix for original issue commited to master 2d93b5394329b556654be1adaa698a83c694ef5d
NH 3.0 GA + Remotion - 1.13.85 and WCF data services
Trying to use projection in OData
http://localhost:2711/TestWcfDataService.svc/TestEntities?$select=Id,FldChar10
and it does not work and generate exception with big stack trace in NH & remotion code
.... ([-1] As TestEntity) .... System.NotSupportedException
The same exception can be reproduce with next test:
public class SelectionTests : LinqTestCase
{
......
[Test]
public void CanDoProjectionWithCast()
{
var lst1 = db.Users.Select(p => new { p1 = p.Name }).ToList();
Assert.AreEqual(3, lst1.Count());
var lst2 = db.Users.Select(p => new { p1 = (p as User).Name }).ToList();
Assert.AreEqual(3, lst2.Count());
}
}