当前位置: 动力学知识库 > 问答 > 编程问答 >

c# - Linq Join using Lambda in VB.NET

问题描述:

I am working on a join using Linq in VB.Net. I am familiar with C# code but VB.Net seems to be difficult. Are there any examples present on the net?

Following is the C# code:

var marketValues = req.SelectedAccounts.Join(assetAllocations, a1 => a1.ModelCode, a2 => a2.APLID, (a1, a2) =>

new { a1, a2 }).Select(o => new

{

MarketValue = o.a1.MarketValue,

AssetAllocationName = o.a2.AssetAllocationName,

AccountID = o.a1.AccountID,

Weight = o.a2.Weight,

MarketValueWeight = ((o.a1.MarketValue * o.a2.Weight) / 100)

}).ToList();

I am not able to convert this into VB.Net.

网友答案:

Should be something like:

Dim marketValues = req.SelectedAccounts.Join(assetAllocations, 
                                             Function(a1) a1.ModelCode, 
                                             Function(a2) a2.APLID, 
                                             Function(a1, a2) New With { a1, a2 }) _
                                       .Select(Function(o) New With 
                                       { 
                                            Key .MarketValue = o.a1.MarketValue, _
                                            Key .AssetAllocationName = o.a2.AssetAllocationName, _
                                            Key .AccountID = o.a1.AccountID, _
                                            Key .Weight = o.a2.Weight, _
                                            Key .MarketValueWeight = ((o.a1.MarketValue * o.a2.Weight) / 100) 
                                        }).ToList()
网友答案:

This may help - a site with example of Linq statements in VB... http://msdn.microsoft.com/en-US/vstudio/bb688088.aspx

分享给朋友:
您可能感兴趣的文章:
随机阅读: