简体   繁体   中英

add properties from another list to an entity

I have spent hours to find the answers on SO. I either don't know how to search or maybe I am asking the question wrong.

Here is the situation:

I have an entity Customers. I get this from my db context like db.Customers. I have users. Those are not in my own database but in the database of the CMS. I can retrieve all the users using a thing like UserManager.GetUsers which will give me a IQueryable of the User object (same User object as in System.Web.Security.

Now I want to create one list containing all the customers, but I want in that same list also the properties from the User object like IsLockedOut and LastActivityDate.

I thought it would be simple by creating a new object that has a property Customer and then the other properties. But everytime I put something in the Linq query as GetUser or IsUserLockedOut I get compile errors like "LINQ to Entities does not recognize the method" or "Only parameterless constructors and initializers are allowed".

Is there any way in getting this to work?

You can't simply add properties to a concrete type using a Linq query - you can certainly create an anonymous type that has a Customer property and whatever other fields you want to add to the anonymous type.

The error you are getting is because you are embedding a custom method call that can't be directly translated to SQL into your Linq query somewhere. Post your Linq query and it will probably be easy to spot.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM