Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/260.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# 我如何才能铸造IQueryable<&燃气轮机;查询IQueryable<;obj.getType()>;?_C#_Linq_Entity Framework_Iqueryable - Fatal编程技术网

C# 我如何才能铸造IQueryable<&燃气轮机;查询IQueryable<;obj.getType()>;?

C# 我如何才能铸造IQueryable<&燃气轮机;查询IQueryable<;obj.getType()>;?,c#,linq,entity-framework,iqueryable,C#,Linq,Entity Framework,Iqueryable,我如何分解这段代码? 我的过滤器返回几种类型的文档。困难的是我对每种类型都有一些查询。。。我想要一个泛型方法来返回正确的查询 谢谢 if(this.comboBoxType.Text.Equals("Vente")) { IQueryable<Vente> queryV = ContexteDAO.ContexteDonnees.Vente .Include("Client")

我如何分解这段代码? 我的过滤器返回几种类型的文档。困难的是我对每种类型都有一些查询。。。我想要一个泛型方法来返回正确的查询

谢谢

        if(this.comboBoxType.Text.Equals("Vente"))
        {
            IQueryable<Vente> queryV = ContexteDAO.ContexteDonnees.Vente
               .Include("Client")
               .Include("Paiement")
               .Include("Employe").OrderBy(v => v.venteID);

            if (this.tbxNomCli.Text != "")
                queryV = queryV.Where(v => v.Client.nom.Contains(this.tbxNomCli.Text));
            if (this.comboBoxEtat.Text != "Tous")
                queryV = queryV.Where(v => v.etat == this.comboBoxEtat.Text);
            if (this.checkBoxDate.Checked)
                queryV = queryV.Where(v => v.date.Equals(this.dateTimePicker.Value.Date));
            if (this.tbxTva.Text != "")
                queryV = queryV.Where(v => v.Client.numEntreprise.Contains(this.tbxTva.Text));
            if (this.checkBoxVendeur.Checked)
            {
                Employe employe = this.comboBoxVendeur.SelectedItem as Employe;
                queryV = queryV.Where(v => v.Employe.login.Equals(employe.login));
            }

            this.documentBindingSource.DataSource = queryV.ToList();
        }
        if (this.comboBoxType.Text.Equals("Commande"))
        {
            IQueryable<Commande> queryC = ContexteDAO.ContexteDonnees.Commande
               .Include("Client")
               .Include("Paiement")
               .Include("Employe").OrderBy(c => c.commandeID);

            if (this.tbxNomCli.Text != "")
                queryC = queryC.Where(v => v.Client.nom.Contains(this.tbxNomCli.Text));
            if (this.comboBoxEtat.Text != "Tous")
                queryC = queryC.Where(v => v.etat == this.comboBoxEtat.Text);
            if (this.checkBoxDate.Checked)
                queryC = queryC.Where(v => v.date.Equals(this.dateTimePicker.Value.Date));
            if (this.tbxTva.Text != "")
                queryC = queryC.Where(v => v.Client.numEntreprise.Contains(this.tbxTva.Text));
            if (this.checkBoxVendeur.Checked)
            {
                Employe employe = this.comboBoxVendeur.SelectedItem as Employe;
                queryC = queryC.Where(v => v.Employe.login.Equals(employe.login));
            }

            this.documentBindingSource.DataSource = queryC.ToList();
        }
if(this.comboBoxType.Text.Equals(“Vente”))
{
IQueryable queryV=ContexteDAO.contextedones.Vente
.包括(“客户”)
.包括(“付款”)
.包括(“雇员”).OrderBy(v=>v.ventid);
如果(this.tbxNomCli.Text!=“”)
queryV=queryV.Where(v=>v.Client.nom.Contains(this.tbxNomCli.Text));
如果(this.comboBoxEtat.Text!=“Tous”)
queryV=queryV.Where(v=>v.etat==this.comboBoxEtat.Text);
if(this.checkBoxDate.Checked)
queryV=queryV.Where(v=>v.date.Equals(this.dateTimePicker.Value.date));
如果(this.tbxTva.Text!=“”)
queryV=queryV.Where(v=>v.Client.numEntreprise.Contains(this.tbxTva.Text));
如果(此checkboxvendour.Checked)
{
Employe Employe=this.comboboxvendur.SelectedItem作为Employe;
queryV=queryV.Where(v=>v.Employe.login.Equals(Employe.login));
}
this.documentBindingSource.DataSource=queryV.ToList();
}
if(this.comboBoxType.Text.Equals(“命令”))
{
IQueryable queryC=ContexteDAO.contextedones.Commande
.包括(“客户”)
.包括(“付款”)
.Include(“Employe”).OrderBy(c=>c.commandeID);
如果(this.tbxNomCli.Text!=“”)
queryC=queryC.Where(v=>v.Client.nom.Contains(this.tbxNomCli.Text));
如果(this.comboBoxEtat.Text!=“Tous”)
queryC=queryC.Where(v=>v.etat==this.comboBoxEtat.Text);
if(this.checkBoxDate.Checked)
queryC=queryC.Where(v=>v.date.Equals(this.dateTimePicker.Value.date));
如果(this.tbxTva.Text!=“”)
queryC=queryC.Where(v=>v.Client.numEntreprise.Contains(this.tbxTva.Text));
如果(此checkboxvendour.Checked)
{
Employe Employe=this.comboboxvendur.SelectedItem作为Employe;
queryC=queryC.Where(v=>v.Employe.login.Equals(Employe.login));
}
this.documentBindingSource.DataSource=queryC.ToList();
}

您可以采用一种通用方法:

public IQueryable<T> GetData<T>( string identifier )
{
     switch( identifier )
     {
         case "Vente":
         {
             return ContexteDAO.ContexteDonnees.Vente
                                               .Include("Client")
                                               .Include("Paiement")
                                               .Include("Employe")
                                               .OrderBy(v => v.venteID);
             // do more stuff

             break;
         }

         // add more cases

         default:
         {
             return null;
         }
     }
}
public IQueryable GetData(字符串标识符)
{
交换机(标识符)
{
案例“Vent”:
{
返回ContexteDAO.contextedones.Vente
.包括(“客户”)
.包括(“付款”)
.包括(“雇员”)
.OrderBy(v=>v.ventid);
//多做事
打破
}
//添加更多案例
违约:
{
返回null;
}
}
}
这个电话看起来像:

IQueryable<Vente> result = GetData<Vente>( "Vente" );
IQueryable结果=获取数据(“通风”);

它可以解决您的问题,但我不喜欢它,因为您需要指定类型并需要一个标识符来执行选择。当您有类似于
GetData(“OtherEntity”)

的内容时,这可能会很快导致异常?从您发布的代码中不清楚我试图将Iqueryable强制转换为Iqueryable@KingKing它仅用于描述查询中正确的返回类型