Wiki Link: [discussion:2138]
Can't do projections to POCO class? 

Aug 11 2009 at 5:33 PM
Given a simple POCO class such as:

public class User { public int Id { get; set; } public string Name { get; set; } public string Password { get; set; } }

When I try a query with projection to itself like so:

using (var context = new Context())
var user = context.User.Select(u => new User { Id = u.Id }).FirstOrDefault();

... I get:

Unhandled Exception: System.ArgumentException: 'Id' is not a member of type 'ORMTest1Model.Users'

... wich comes from the method ValidateMemberInitArgs(...) from System.Linq.Expressions.Expression (use Reflector).

In this method, the type from binding.Member.DeclaringType is of type PocoAdapters.UserAdapter (the generated one) and the type from variable "type" is of type User (the POCO class).

So... for some reason, it's mixing thing up.

Interestingly, if I create a class MyUser which is the exact copy of the poco class User, it works fine and both types at ValidateMemberInitArgs(...) are of type MyUser.

Can anyone reproduce the issue and shed a light on the solution?


Oct 11 2009 at 7:19 AM
Any updates to a better work-around other than having to recreate a class to hold the same property values?

Thank you.

Oct 30 2010 at 6:23 AM
I think I figured out why this is happening.

MsSql allows for capital letters in table names, but MySql does not.
So if you create your poco adapter from an mssql entity model which contains capital letters in table names, and use it to query a mysql database, you will get this type of error.

In order to fix this, I just renamed my tables to all lowercase.

Page view tracker