0

I have added a property to a partial class of a model. This property will retrieve a model from database according to property value.

Example:

class movie
{
    int language;
}

partial movie 
{
    public Language SpokenLanguage
    {
       get
       {
          var currLang = db.Languages.Where(ml => ml.ID == this.language).FirstOrDefault();
          return currLang;
       }
   }
}

Is this approach will affect application performance when I retrieve a list of movies?

If so what is the equivalent and better performance?

tereško
  • 58,060
  • 25
  • 98
  • 150
  • No, that field won't be considered by EF, but why do you do such thing? You can add this relation in EF, why do you do it manually? – Wojciech Kulik Jun 23 '13 at 13:17
  • I have a column with comma seperated Ids value – Mohamed Magdy Jun 24 '13 at 11:07
  • Wow, it's pretty wrong. It isn't right way to create relations between tables. You should have a link table for many-to-many relation. Read about that kind of relationship and how to properly do it. – Wojciech Kulik Jun 24 '13 at 14:51

1 Answers1

0

EF will ignore the SpokenLanguage property in your case.

However, you can make EF retrieve the SpokenLanguage using a INNER JOIN by adding a relation in your model between the two tables.

You can also make it retrieve the SpokenLanguage lazily (on demand)-it will actually make a better version on what you wrote, but if you are sure you want to print the language label in your view, it's better to retrieve it using a INNER JOIN.

alex.net
  • 286
  • 1
  • 6