English 中文(简体)
如何在需要时只使用独一无二的字节,而不是单独使用。
原标题:How to apply group by instead of distinct when need only unique rows?

I working on ap.net razor page LINQ to function . i 问题一:

<代码>viewmodel PropertyLPOvm

<><><>>>>>

如果有2或3行,每样一行都是一样的,再三重复,则只需要归还一个独一无二或独一无二的行,因为其他行是重复的。

确切地说,需要用群体而不是不同的群体来恢复不同的结果。

i 尝试使用以下不同的词语,但不得退回不同的行文。

这样一来解决问题

 public List<AssetLPOvm> GetAllLpoDetails(string SelectedCompany)
    {
    


        var AssetBranches = _unitOFWorkAsset.AssetBranches.GetList(x => x.CompanyNo == SelectedCompany && Convert.ToInt32(x.UserID) > 0 );
        

        var NewAssetTagging = _unitOFWorkAsset.NewAssetTagging.GetList(x => x.LPONo > 0);
var result = (from assetBranch in AssetBranches
               join user in Users on assetBranch.UserID equals user.UserID
               join assetTagging in NewAssetTagging on Convert.ToDecimal(assetBranch.LPONO) equals assetTagging.LPONo
     
               select new AssetLPOvm
               {
                   AssetItemNo= assetBranch.AssetItemNo,
                   SupplierName=assetTagging.SupplierName,
                   SelectedMCUName= assetBranch.SelectedMCUName,
                   AssetOwner=assetBranch.AssetOwner,
                   ItemCode=assetBranch.ItemCode,
           
           
                   Qty = assetBranch.Qty,
                   LPONO = assetBranch.LPONO
                                }).Distinct().ToList();
 return result;
}

    public class AssetLPOvm
    {
     

        public string LPONO { get; set; }

        public string AssetItemNo { get; set; }

        public string SupplierName { get; set; }

        public string SelectedMCUName { get; set; }

        public string AssetOwner { get; set; }

        public double Qty { get; set; }

        public string ItemCode { get; set; }


    }
  public class AssetBranches
    {
      [Key]
      [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
      public decimal ID {get;set;}
      public string AssetItemNo { get; set; }
      public string SelectedMCUName { get; set; }
      public string AssetOwner { get; set; }
      public double Qty { get; set; }
      public string LPONO { get; set; }
      public string ItemCode { get; set; }

       }
    public class NewAssetTagging
    {
        [Key]
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public decimal ID { get; set; }
        public decimal? LPONo { get; set; }
        public decimal? SupplierNumber { get; set; }

    }
public class User
{
    public string vLoginName {get;set;}
    public string UserName {get;set;}
}

如何通过功能而不是利用不同功能来分组?

我尝试的是独一无二的,但又不回头。

问题回答

I think you can use GroupBy as below. .GroupBy(x=>x.ItemCode).Select(x=>x.First()).ToList()

各位可以尝试:

.GroupBy(p => new { p.AssetItemNo, p.SupplierName, p.SelectedMCUName, p.AssetOwner, p.ItemCode, p.Qty,p.LPONO}).ToList();




相关问题
Export tables from SQL Server to be imported to Oracle 10g

I m trying to export some tables from SQL Server 2005 and then create those tables and populate them in Oracle. I have about 10 tables, varying from 4 columns up to 25. I m not using any constraints/...

SQL server: Can NT accounts be mapped to SQL server accounts

In our database we have an SQL server account that has the correct roles to access some of the databases. We are now switching to windows authentication and I was wondering if we can create a NT user ...

SQL Server 2000, ADO 2.8, VB6

How to determine if a Transaction is active i.e. before issuing Begin Transaction I want to ensure that no previous transaction are open.. the platform is VB6, MS-SQL Server 2000 and ADO 2.8

热门标签