Suppose I have project MyData, then I add MyDb.edmx with EF wizard. In My database, I have table Person. Then I will get an entity Person in EF model.
Then I want to extend this Person by partial class in a separated file person.cs like:
namespace MyData
{
public partial class Person
{
[DataMember]
public int MyTotal
{
get
{
int count = 0;
using (MyEntities ctx = new MyEntities())
{
//run some linq to get calc based on other entities
}
return count;
}
}
}
It works fine. Then at client I can get the entity Person instance with property MyTotal. Problem is: When I want to list of Person at client side(such silverlight), the performance is very bad because for each instance of Person, it will cause on SQL DB connection and run one SQL for MyTotal.
If I have more ten one such kind of extending property, the performance will be very bad. How to resolve this problem?