c# - Dynamically set the table name in LINQ query -


I am working on the data warehouse application and we have 4 tables where the schema is the same. The only difference between those tables The table name is the same.

Table example:

  • ps_Contractor
  • ps_Employee
  • ps_Union

    ps_NonUnion

    Schema

    • ID
    • hourly
    • profit
    • total

      Now I need to prepare 4 reports based on these tables. Instead of writing 4 different LINQ queries, I would like to write a single query where I can pass the table name dynamically.

      Question How can I pass the table name dynamically after the LINQ query?

        var data = (in _dbcontext.ps_Contractor in q _dbcontext.log in _l .include .id is l.tablelogid where q.hourly = 8 select new {hour = Q.hourly, profit = q.benefit, total = q.total, log = l.message} .OoLS ();   

      I have seen all the similar questions suggested by stack overflow I do not want to use ExecuteStoreQuery.

      What options do I have?

      < P> If all the tables have the same columns, then one of those tables and partial it will be for example:
        // the public partial square of the organization ps_Contractor: ICommonInterface {} {/ p>  public partial Classroom table 2: ICommonInterface {}   

      In the search method I have passed the IEnumerable & lt; ICommonInterface & gt; or IQueryable & lt; ICommonInterface & gt; and apply that query to it, all you have to do is pass that different tables in the search method. Or you can also do the normal type of normal type of code ICommonInterface and use it to use the query. Public void example (IQueryable & lt; ICommonInterface & gt; data source) {var data = (data in q is similar to l.tablelogid in qd at _dbcontext.log in data essence, Where q.hourly = 8 select New {hourly = q.hourly, profit = q.benefit, total = q.total, log = l.message}. Olist ();} example (_dbcontext.ps_Contractor.ascableable) )

      This is just a sample that I have just tested:

        Public category repository {Private list & gt; Get & gt; GetData ( IQueryable & lt; IContractor & gt; Data) name. Olilist ();} public address Snatch & gt; String & gt; GetFullTime () using (var references = New TestDbEntities ()) {GetData (ref.fTContractors.AsQueryable ());}} Public List & gt; GetPartTime (using the terms (var references = new testDBTT) {GetData (References.PTCTrectors.Secenable)}}}}   

      Organizations:

        Public Interface ICentractor {Ent ID {get; Set;} string name {get; Set;}} Public Partial Class FTContractor: IC Contractor {Public Ent ID (Receive; Set;} Public String Name {get} Set;}} Public Partial Category PTContractor: IC Contractor {Public Ent ID (get; Set;} Public String Name {Get; set;}}   

      Test:

        [TestMethod] public zero temp () {var tester = new repository (); var ft = Tester.GetFullTime (); Var pt = tester.GetPartTime (); assurance .requal (3, feet); assurance .requal (4, pt count); }   

      Databases contain only id and names columns

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -