none
1 object to multiple table binding RRS feed

  • Question

  • Good morning.
    I have a little problem using Entity Framework.

    I have a (non mine) multiple instance application installed on the same database; instances are differenced using a table prefix
    AZPOST
    BCPOST
    FRPOST

    Using EntityFramework database first, i have my good model.edmx and it works very good.
    My problem is that i have to perform same queries on the same database, and it's very annoing to write them 4 times:

    switch (code)
    {
       case "AZ":
         return AZPOST.Where(h=>h.id=10);
       case "BC":
         return BCPOST.Where(h=>h.id=10);
    
    //and go on
    }

    I was wondering if is there any way, using EntityFramework, to create a big generic POST object and use them to perform operation, and have a single database access, something like this:

    POST pt = Database.GetPosts(code).Where(h=>h.id = 10);

    And so on.
    Can you give me some advices?
    Thank you a lot!


    Il saggio è quello che sa di non sapere
    Wednesday, October 5, 2011 3:45 PM

Answers

  • Hi VincentITA,

    You can use Reflactor to retrieve the ObjectSet by the table name:

      using (var context= new EFTestEntities())
                {
                    IEnumerable<Employee> test = (IEnumerable<Employee>)context.GetType().GetProperty("Employees").GetValue(context, null);
                    
                }
    

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, October 7, 2011 3:40 AM
    Moderator

All replies

  • No reply? No advice?
    Il saggio è quello che sa di non sapere
    Thursday, October 6, 2011 7:50 PM
  • Hi VincentITA,

    You can use Reflactor to retrieve the ObjectSet by the table name:

      using (var context= new EFTestEntities())
                {
                    IEnumerable<Employee> test = (IEnumerable<Employee>)context.GetType().GetProperty("Employees").GetValue(context, null);
                    
                }
    

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, October 7, 2011 3:40 AM
    Moderator
  • So i can get BCPOST generic object even calling get table on AB post?
    I mean, will this work?

     using (var context= new EFTestEntities())
                {
                    IEnumerable<Employee> test = (IEnumerable<BCEmployee>)context.GetType().GetProperty("ABEmployees").GetValue(context, null);
                    
                }
    
    


    Il saggio è quello che sa di non sapere
    Monday, October 31, 2011 11:04 AM