entity framework - add a dynamic field at runtime

Job ID: 33340986

Budget: $10 – $30 USD

Hi all

I'm using Dynamic Linq to select a few fields from a database query

Lets say I have following class

Class User
Property LastName as string
Property Email as string
End Class

But I want to call the query like this

dim q= MyContext.Set("User").Select("new (LastName, FirstName)")
I obviously get an error

System.Linq.Dynamic.Core.Exceptions.ParseException: 'No property or field 'FirstName' exists in type 'User''

Even though I have the field in the database

So the question is: How can I tell EF at run time, that the User Class has a field FirstName. Even though it was not declared in code?

I looked at all the documentation about OnModelCreating, but can't seem a way to add a new property, only configure existing/known properties.

if you can fix this issue, please send a fixed-price quote

thanks
Related categories: .NET SQL Microsoft SQL Server LINQ