I have some functionality that needs to be 'selectable' as an option for certain objects in my database, but the actual code behind each method is far too complicated to be serialized into a database. They also cannot be SQL Stored Procedures.
So basically, I have a static List<T>
of these functions. Is there a standard way of associating these with objects in my database? For instance..
var functions = new static List<Omega>{
new Omega {
Id = 1, // this would be useful to a database, but nothing really sets it.
Name = "Some Name",开发者_StackOverflow // this isn't useful. It's a string literal
Function = // this may be a Method, or a Lambda Expression, or something else.
}
};
class Psi {
Guid Id { get; set; }
Omega Omega { get; set; } // how can I keep a hard-reference here?
}
Ok, I am not sure if I got it correctly. Delegates are serializable and therefore they can be stored into a database, e.g. using NH. There are some limitation but serializing delegates is an adventurous journey anyway:).
If it is not a viable way, then you could try to implement all your "functions" as static methods. Class and method name can be stored in a table column and invoked via reflection.
精彩评论