如何在LINQ查询中获取多个结果集(使用实体框架 [英] How to get multiple result sets in LINQ query(with Entity Framework

查看:107
本文介绍了如何在LINQ查询中获取多个结果集(使用实体框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我想从LINQ查询(使用Entity Framework 4.1)中获得多个结果集.

正如我所做的一个示例示例正在工作的那样,但我认为这不是正确的方法.

Hello All,

I want to get multiple results sets from LINQ query(with Entity Framework 4.1).

As i did one sample example which is working but i think this is not a proper way.

var promotionProductObject = (from p in _dataEntities.CMS_Promotion
                              join pa in _dataEntities.CMS_ZO_PromotionArticle
                              on p.autPromotionId equals pa.intPromotionId
                              where (pa.intDeletedBy == null) && (pa.datDeletedOn == null) && (p.autPromotionId == 14)
                                      select new
                                      {
                                          p,
                                          productlist = from a in _dataEntities.Artikels
                                                        where pa.decArticleId == a.ID
                                                        select a
                                      }).ToList();


在上面的示例中,我从促销表和商品表中检索值,它们之间的关系为促销1 ==> M促销商品1 ==> M商品
即我希望基于promotinId的表格中的所有文章列表,例如1004.


In the above example I am retrieving the value from promotion table and article table and the relation between them is promotion 1==>M promotionArtilce 1==>M article
i.e. i want all the list of article from the table based on promotinId eg 1004.

for (int i = 0; i < promotionProductObject.Count(); i++)
        {
            productList1 = promotionProductObject.ToList()[i].productlist.ToList();
            productList.Add(productList1);
        }
        gvArticleDetails.DataSource = productList.ToList();
        gvArticleDetails.DataBind();

// in RowDataBound event
lblArticleNumber.Text = GetLocalResourceObject("lblArticleNumber") + productList.ToList()[_columnCount].ToList()[0].ArtikelNummer;


在这种情况下,当我将值与文章的网格绑定时,我不能使用eval属性,因此,我必须使用行databound事件(我不想使用).
有没有其他好的方法可以使用Linq查询处理多个结果集?

感谢支持.


In this case when I bind the value with grid for article, I cant use the eval property, so alternately I have to use row databound event (which I dont want to use).

Is there any another good way to work on multiple result set with Linq query

Thank for support.

推荐答案

逻辑很神奇
由我自己解决:解决方案.

我发现了两种方法,通过这些方法,我们可以在gridview中将数据与Eval绑定.
LOGIC IS MAGIC
Solved by My Self: Solution.

There are two methods i have found, by which we can bind the data with Eval in gridview.
List articleList = new List();
    
    List articleList1 = new List();
#region Method I
        var promotionProductObject = (from p in _dataEntities.Promotions
                                      join pa in _dataEntities.PromotionArticles
                                      on p.PromotionId equals pa.PromotionId
                                      where (pa.DeletedBy == null) && (pa.DeletedOn == null) && (p.PromotionId == 14)
                                      select new
                                      {
                                          p,
                                          productlist = (from a in _dataEntities.Artikels
                                                         where pa.ArticleId == a.ID
                                                         select a)
                                      }).ToList();

        if (promotionProductObject != null)
        {
            for (int i = 0; i < promotionProductObject.Count(); i++)
            {
                Artikel article = promotionProductObject[i].productlist.ToList()[0];
                articleList.Add(article);
            }

            grdArticleDetails.DataSource = articleList;
            grdArticleDetails.DataBind();
        }

        #endregion Method I

        #region Method II
        var promotionArtilceObject = (from p in _dataEntities.Promotions
                                      join pa in _dataEntities.PromotionArticles
                                      on p.PromotionId equals pa.PromotionId
                                      join a in _dataEntities.Artikels
                                      on pa.ArticleId equals a.ID
                                      where (pa.DeletedBy == null) 
                                      && (pa.DeletedOn == null) && (p.PromotionId == 14)
                                      select new
                                      {
                                          p,//Promotion
                                          productList = a // Article
                                      }).ToList();

        if (promotionArtilceObject != null)
        {
            for (int i = 0; i < promotionArtilceObject.Count(); i++)
            {
                articleList1.Add(promotionArtilceObject[i].productList);
            }
            grdArticleDetails1.DataSource = articleList1;
            grdArticleDetails1.DataBind();
        }
        #endregion Method II
    }



可以通过-
访问该值 lblArticleName.Text = articleList1[_rowCount1].Bezeichnung;



And the value can be access by -
lblArticleName.Text = articleList1[_rowCount1].Bezeichnung;



http://blogs.msdn.com/b/dditweb/archive/2008/05/06/linq-to-sql-and-multiple-result-sets-in-stored-procedures.aspx [
Hi
http://blogs.msdn.com/b/dditweb/archive/2008/05/06/linq-to-sql-and-multiple-result-sets-in-stored-procedures.aspx[^]


这篇关于如何在LINQ查询中获取多个结果集(使用实体框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆