Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
带枚举的C#简单linq_C#_Linq - Fatal编程技术网

带枚举的C#简单linq

带枚举的C#简单linq,c#,linq,C#,Linq,我得到了这样一个枚举: public enum PlatForms { AAA=1, BBB=2, CCC=3 } 还有这样一个函数: public List<Something> GetSomething(PlatForms pf) { switch(pf) { case PlatForms.AAA: var some = context.table1.Where(x => x.Prop ==

我得到了这样一个枚举:

public enum PlatForms
{
    AAA=1,
    BBB=2,
    CCC=3
}
还有这样一个函数:

public List<Something> GetSomething(PlatForms pf)
{
    switch(pf)
    {
        case PlatForms.AAA:
            var some = context.table1.Where(x => x.Prop == true);
            break;
        case PlatForms.BBB:
            var some2 = context.table2.Where(x => x.Prop == true);
            break;
        default:
            break;

    }
    //do convert;
    //
}
public List GetSomething(平台pf)
{
开关(pf)
{
case PlatForms.AAA:
var some=context.table1.Where(x=>x.Prop==true);
打破
case PlatForms.BBB:
var some2=context.table2.Where(x=>x.Prop==true);
打破
违约:
打破
}
//一定要皈依;
//
}

不同之处在于表名不同。如何重写代码以使其变得简单?

需要这样做吗

您不希望每次都运行这个字典代码,所以一旦有了上下文,就可以初始化字典

        var tableTranslation = new Dictionary<Platforms, Context>();
        tableTranslation.Add(Platforms.AAA, context.table1);
        tableTranslation.Add(Platforms.BBB, context.table2);

这是否符合您的要求?

使用
DbContext.Set()
并将泛型类型传递给您的方法。什么是
Something
,即如何使
some
somet2
最终成为相同类型的
Something
        var some = tableTranslation[pf].Where(x => x.Prop == true);
        //do convert