I have a “Literal” class that defines a text value and an ID. I want to build a static method that is simply “FromValue(string)” within the Literal class (LINQ to SQL), so that it’ll return the proper Literal instance from a given value.
I’m having some trouble figuring out how to do this, though. I mean, I can call it in code everytime I need it, but it would be much more convenient and time saving to just wrap it into the class itself.
Any ideas?
using System;
using System.Linq;
namespace Context
{
public partial class Literal
{
public static Literal FromValue(string value)
{
// linq code, how do I reference the existing data context?
return null;
}
}
}
What “existing data context”? There may well be more than one data context alive at the point of the call to
FromValue, e.g.:You’ll have to pass it as parameter, there really isn’t any better way.
Also note that you won’t be able to use
FromLiteralin your LINQ2SQL queries (since the query parser and translator has no idea what it does).