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?
Thanks!
(link to same question in project's discussion list: http://code.msdn.microsoft.com/EFPocoAdapter/Thread/View.aspx?ThreadId=2138)