1

With many efforts in my side, i get the following code executing:

var instance = Activator.CreateInstance("Assemblyname", "TypeName").Unwrap();
//Code to fill instance using reflection
DbContext.Set(instance.GetType()).Add(instance);
DbContext.SaveChanges();

now i want to achieve something like following code:

var u = DbContext.Users;
var z = from y in u
where y.Email =="some email"
select y;

but i want get u Dynamically, i need something first piece of code to reference existent entity inside DbContext

2 Answers 2

2

You are probably looking for

DbContext.Set(typeof(User))

http://msdn.microsoft.com/en-us/library/gg679544(v=vs.103).aspx

There is a generic version as well:

DbContext.Set<User>()

Sign up to request clarification or add additional context in comments.

2 Comments

yes i need generic version, but my problem is that it must be reference dynamically, like first piece of code
the exact problem is that one time i need user, another time another type
1

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.