I've looked all over the 开发者_JAVA技巧net and can't seem to find a decent solution. I'm a noob regarding Entity Framework. What I've been able to work with I really like. In past projects, I've been able to pull a Dictionary of objects that I can use later like this:
Dictionary<string, MyBaseType> myTypes = new Dictionary<string, MyBaseType>();
var types = Assembly.GetExecutingAssembly().GetTypes()
.Where(t => t.BaseType != null && t.BaseType.Name.Equals("MyBaseType")).ToArray();
object ct;
foreach (Type c in types)
{
ct = Activator.CreateInstance(c);
myTypes.Add(ct.GetType().Name, ct as MyBaseType);
}
var myob = myTypes["SomeName"];
myob.DoFoo(); // this is a method of my basetype class or my interface
I need to do something similar for an MVC w/ EF4 project. I tried using EntityObject as the base type, but for whatever reason, the Executing Assembly won't reflect them.
Any ideas?
You have to check:
- What is the base class for your EF objects - mine derive directly from System.Object for example.
- That you are looking for them in the right assembly - are they declared in the assembly that executes the code from your sample?
精彩评论