English 中文(简体)
Linq 询问显示适当的秩序
原标题:Linq query to display a proper sort order

表1:概览

LookUpID
LookUpName
Desc
DisplayOrder

表2:账单

BillingRateID
BillingRate
ClientID
LookupID

我希望能展示出国名(按账单费率)。

DataContext DataContext1 = new DataContext1(AppSettings.ConnectionString);

return ( from Lookups in DataContext1.Lookups
         join BillingRates in DataContext1.BillingRates
         on  Lookups.LookupID equals BillingRates.LookupID
         orderby BillingRates.BillingRate
         select new
         {
             Lookups.LookupID,
             Lookups.LookupName,
             Lookups.Desc
         }).Distinct();

它给了我所有这段话,因此我使用了区别。 查询名称仍然基于账单率。

我是新到的。 欢迎任何要点。

最佳回答

为什么最终不只填写<代码>OrderBy?

return (from Lookups in DataContext1.Lookups 
     join BillingRates in DataContext1.BillingRates 
     on  Lookups.LookupID equals BillingRates.LookupID 
     select new 
     { 
         Lookups.LookupID, 
         Lookups.LookupName, 
         Lookups.Desc,
         BillingRates.BillingRate
     })
     .GroupBy(x => x.LookupID)
     .Select(y => y.OrderByDescending(x => x.BillingRate).First())
     .OrderByDescending(x => x.BillingRate);

http://www.un.org。 我感到困惑,但试图做到以下几点,让我知道这是否有助于。

问题回答

首先,如果你建立了外国关键关系,国家扫盲中心将自动为你建立联合关系,因此,这只是:

 DataContext1.Lookups.Max(LkUp => LkUp.BillingRate.BillingRate)

否则(明确加入)

return ( from Lookups in DataContext1.Lookups   
     join BillingRates in DataContext1.BillingRates   
     on  Lookups.LookupID equals BillingRates.LookupID 
     orderby BillingRates.BillingRate desc
     select new   
     {   
         Lookups.LookupID,   
         Lookups.LookupName,   
         Lookups.Desc,  
         BillingRates.BillingRate  
     }).First();




相关问题
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. ...

热门标签