English 中文(简体)
2 linq 同一电网的询问
原标题:2 linq queries to same gridview
  • 时间:2011-11-24 10:10:12
  •  标签:
  • c#
  • linq
  • web

I would like to "combine" to linq queries into the same gridview. Though I don t think I could use innerjoin on this. The queries get orders from the database, and I have 2 tables with orders from different places. In the gridview I want to display all orders from first table and second table. Like this:

OrderID - Item - Amount etc ---From table 1
OrderID - Item - Amount etc ---From table 2
etc..

我目前从第一个桌上接到命令的问询是:

var query = from o in db.Orders
            join y in db.OrderLines on o.OrderID equals y.OrderID
            join x in db.Products on y.ItemNumber equals x.ItemNumber
            where o.AccountNumber == AppSession.CurrentLoginTicket.AccountNumber
            select new
            {
                o.OrderID,
                o.AxaptaSalesId,
                y.ItemNumber,
                x.Name,
                x.ProductFormatName,
                y.Quantity,
                y.Price,
                Status = dltRep.getOrderStatus(o.OrderID, o.AxaptaSalesId, y.ItemNumber).Substring(0, dltRep.getOrderStatus(o.OrderID, o.AxaptaSalesId, y.ItemNumber).LastIndexOf("|")),
                Levering = dltRep.getOrderStatus(o.OrderID, o.AxaptaSalesId, y.ItemNumber).Substring(dltRep.getOrderStatus(o.OrderID, o.AxaptaSalesId, y.ItemNumber).LastIndexOf("|")).Replace("|", "")
            };

另一表将有相同的资料。 它叫AxSale。

我希望这一点是可能的,有人可以帮助我:

<>strong>EDIT:新的“问题”

I wan t to get the variable createdDate to be the first element x.CreatedDate in either the first linq seq. or the second. How do I do this?

var created = purchases.OrderByDescending(x => x.CreatedDate).
                Select(x => new { x.CreatedDate, x.LineSupplierAccountNO }).
                GroupBy(x => x.LineSupplierAccountNO);

if (created.Count() > 1)
{
    created = purchases.OrderBy(x => x.CreatedDate).
                Select(x => new { x.CreatedDate, x.LineSupplierAccountNO }).
                GroupBy(x => x.LineSupplierAccountNO);
}

var createdDate = created.FirstOrDefault();

Solution code:

var created = purchases.OrderBy(x => x.CreatedDate).Select(x => x);

if (created.GroupBy(x => x.LineSupplierAccountNO).Count() > 1)
{
    created = purchases.OrderByDescending(x => x.CreatedDate).Select(x => x);
}

var createdDate = created.First().CreatedDate;
最佳回答
问题回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签