If I can't use datacontext in a static
        Posted  
        
            by Richard77
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Richard77
        
        
        
        Published on 2010-04-18T21:46:01Z
        Indexed on 
            2010/04/18
            21:53 UTC
        
        
        Read the original article
        Hit count: 169
        
c#3.0
Hello,
I've got this
public static class MyClassHelper
{
  DataContex db = new DataContext();
  public static Type MyMethod()
  {
    //Do Something with db
    // such as db.myTable
  }
}
I'm getting the following error: "An object reference is required for the non-static field, method or property..."
Is there anyway to get around this?
How about this. I've an object that contains only integers, which is fine for all the internal functionings as it allows me to link tables. But occasionaly, I need to display some information to the user. That's why, I'd like to create a static method so it would read the integer, look up in the DB, and display a name instead of a number.
I want it to be a static method so that I can use it in my View template.
Thanks for helping
© Stack Overflow or respective owner