0

With Entity Framework you can easily get data from the database doing something like this:

var allBooks = BookContext.Books;

So this code returns all books from the "Book" table.

But I'm getting a string back that tells me from what "table" I need the data from. So I have something like this:

public void GetData(string entity) // entity = "Book"
{
    // Get data using the "entity" string from BookContext
    BookContext.FromString(entity); // for exmaple
}

Is there a way to retrieve data from the BookContext using a string?

2
  • The possible duplicate applies to EF6, this question is about EF7. Commented Nov 29, 2015 at 14:39
  • @GertArnold That's true. But I think the answer also works for EF7. Commented Nov 30, 2015 at 2:21

1 Answer 1

0

A quick look to the source code of EF7 reveals that, in contrast to the previous versions, there isn't any Set(Type entityType) method in the DbContext class. There is only the it's generic version Set<TEntity>().

So I think, it isn't possible without using some obscure reflection. (Obscure because EF7 doesn't have any non-generic version of the DbSet class which makes working with the set obtained by the reflection quite difficult)

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.