0

In my ASP.NET web site I created new Entity Data Model and connected it with my MsSql database. Now I can use Model.Student class but that class don't have methods. I tried to add extension methods like

public static class Functions{
     public static double calculateStudentScore(this Model.Student s){
          //implementation
     }
}

When I create new Student and try to call my method, I can't see it, why is so?

For example lets suppose s is type of Student

double score=s.calculateStudentScore();//I can't see my calculateStudentScore method
MrD
  • 2,423
  • 3
  • 33
  • 57

1 Answers1

1

Your EF model is a partial class. While I agree in principle that the extension should be visible, in the meantime, just add a new file, and add the method to the class.

Darek
  • 4,687
  • 31
  • 47
  • It's OK now, I forgot static keyword in method declaration. Thx to all of you! – MrD Aug 01 '12 at 00:04
  • 1
    That begs an interesting question: to extent or not to extent? Which way is better? faster? more maintainbale? – Darek Aug 01 '12 at 00:39
  • Well I done this way because it is easier to maintain. If I change model, there is no problem with my methods :) – MrD Aug 01 '12 at 18:29