Change table name at runtime

后端 未结 7 1902
陌清茗
陌清茗 2020-12-17 03:22

Lets suppose that I have a db table with name Employee and a respective EF 6.0 db-first model.

Getting all rows of table Employee is done through q

7条回答
  •  佛祖请我去吃肉
    2020-12-17 04:16

    Why not use some good old fashioned polymorphism?

    partial class Employee : IEmployee { }
    partial class HistoricalEmployee : IEmployee { }
    
    interface IEmployee {
        public string Name { get; set; }
    }
    
    void PrintEmployeeName(IEmployee employee)
    {
        Debug.WriteLine(employee.Name);
    }
    
    PrintEmployeeName(context.Employees.First());
    PrintEmployeeName(context.HistoricalEmployees.First());
    

提交回复
热议问题