Reputation: 93
Hi my first question here so forgive me if its not asked in the correct manner. I'm new to the entity framework and have a database first model.edmx file setup. What I would like to know is if there is a way to setup a property on an entity that returns a method: eg.I have a Customer entity with various properties. Using Linq I could do something like context.Customers.ToList(); to return all the customers. How could I create a property/method that would look like this context.Customers.getAll(); I could then create others like context.Customers.getVIP(); with cetain conditions.
Upvotes: 0
Views: 442
Reputation: 613
The answer provided above is the proper and the right way to do it. But, if for any reason you want to do it the other way, you can have a partial class for your data context
public partial class EntityContext
{
public List<Plant> GetAllCusomters()
{
return Customers.ToList();
}
}
A word of warning though, this is by no means a proper way to do it and certainly not the recommended approach.
Upvotes: 1
Reputation: 1537
You need a class that having all logics of an entity...
This link will help you - Implementing Repository Pattern With Entity Framework
Upvotes: 4