Talon
Talon

Reputation: 3593

Dynamic Tables of a Common Type - Entity Framework

I have an Entity called "MyEntity".

Now, In my database, every month a new table is created called "MyEntityJan2017", the following month will be "MyEntityFeb2017" etc...

Normally I return my entities like this:

public DbSet<MyEntity> MyEntity{ get; set; }

But I can't do this here as there is no such class as "MyEntityJan2017"

The repository methods for these tables use the returned DbSet and query them using Linq.

How do I return a DbSet for dynamically created tables?

The only solution I have so far is to query these tables the old fashioned way as below but I'd rather not.

var resultSet = dataContext.Database.SqlQuery<MyEntity>(sqlQuery, paramList);

Upvotes: 0

Views: 513

Answers (1)

Talon
Talon

Reputation: 3593

The basic answer to this is that you can't with EF. As Yashveer suggested, it is best to simply use a stored proc to return the data that is needed,

Upvotes: 1

Related Questions