A
Andy B
I have a class that I want to make static but it uses some objects that are
instance objects. I keep getting a compiler error saying something about
using instance objects in a static class or method is not allowed. How do
you do this if you really need a static class but also have to use these
instance objects in them? If you need a simple example of what I am trying
to do, it is below:
imports Data.EternityRecordsEntities
namespace News
public static class News
EternityRecordsEntities NewsContext as new EternityRecordsEntities()
'*** A simple method to show what I am looking for. Also see above code.
public static function CreateNews(Title as string, Description as string,
Body as string) as integer
'*** Do whatever required to validate Title, Description and Body.
'*** Now use the entity framework model to insert the values above.
if (NewsContext.InsertNewsArticle(Title, Description, Body) = 0) '***
Creating news article succeeded.
'*** Log the action somehow.
Log.WriteEntry("Created news article '"+Title+"'.")
else
'*** Things didn't quite work out...
Log.WriteEntry("Failed to create news article '"+Title+"'.")
end if
end class
end namespace
instance objects. I keep getting a compiler error saying something about
using instance objects in a static class or method is not allowed. How do
you do this if you really need a static class but also have to use these
instance objects in them? If you need a simple example of what I am trying
to do, it is below:
imports Data.EternityRecordsEntities
namespace News
public static class News
EternityRecordsEntities NewsContext as new EternityRecordsEntities()
'*** A simple method to show what I am looking for. Also see above code.
public static function CreateNews(Title as string, Description as string,
Body as string) as integer
'*** Do whatever required to validate Title, Description and Body.
'*** Now use the entity framework model to insert the values above.
if (NewsContext.InsertNewsArticle(Title, Description, Body) = 0) '***
Creating news article succeeded.
'*** Log the action somehow.
Log.WriteEntry("Created news article '"+Title+"'.")
else
'*** Things didn't quite work out...
Log.WriteEntry("Failed to create news article '"+Title+"'.")
end if
end class
end namespace