I have condition where i have to join two different types of array to form a new array.
Let's see the class where condition should be created.
public class MutualFundParameter
{
public int Id { get; set; }
public string AcNo { get; set; }
public string CustomerName { get; set; }
}
public class VoucherDetails
{
public int Id { get; set; }
public int AcNo { get; set; }
public decimal Amount { get; set; }
public int MasterId { get; set; }
}
public class VoucherMaster
{
public int Id { get; set; }
public DateTime DateTime { get; set; }
public ICollection<VoucherDetails> VoucherDetails { get; set; }
}
New let's add some data into that object
// mutual fund parameter
var mutualFundParameters = new List<MutualFundParameter>
{
new MutualFundParameter { Id = 1, AcNo = "001", CustomerName = "Ram" },
new MutualFundParameter { Id = 2, AcNo = "002", CustomerName = "Shyam" },
new MutualFundParameter { Id = 3, AcNo = "003", CustomerName = "Hari" },
new MutualFundParameter { Id = 4, AcNo = "004", CustomerName = "Gita" },
new MutualFundParameter { Id = 5, AcNo = "005", CustomerName = "Sita" },
};
// voucher details
var voucherDetails = new List<VoucherDetails>
{
new VoucherDetails { Id = 1, AcNo = 001, Amount = 10.00M, MasterId = 1 },
new VoucherDetails { Id = 2, AcNo = 001, Amount = 120.00M, MasterId = 1 },
new VoucherDetails { Id = 3, AcNo = 002, Amount = 20.00M, MasterId = 1 },
new VoucherDetails { Id = 4, AcNo = 002, Amount = 120.00M, MasterId = 1 },
new VoucherDetails { Id = 5, AcNo = 002, Amount = 30.00M, MasterId = 1 },
new VoucherDetails { Id = 6, AcNo = 002, Amount = 20.00M, MasterId = 1 },
new VoucherDetails { Id = 7, AcNo = 003, Amount = 20.00M, MasterId = 1 },
new VoucherDetails { Id = 8, AcNo = 003, Amount = 20.00M, MasterId = 1 },
new VoucherDetails { Id = 9, AcNo = 003, Amount = 20.00M, MasterId = 1 },
new VoucherDetails { Id = 10, AcNo = 004, Amount = 10.00M, MasterId = 2 },
new VoucherDetails { Id = 11, AcNo = 005, Amount = 20.00M, MasterId = 2 },
new VoucherDetails { Id = 12, AcNo = 006, Amount = 30.00M, MasterId = 2 },
new VoucherDetails { Id = 13, AcNo = 007, Amount = 40.00M, MasterId = 2 },
new VoucherDetails { Id = 14, AcNo = 008, Amount = 50.00M, MasterId = 2 },
new VoucherDetails { Id = 15, AcNo = 009, Amount = 60.00M, MasterId = 2 },
new VoucherDetails { Id = 16, AcNo = 001, Amount = 70.00M, MasterId = 2 },
};
// voucher
var voucherMasters = new List<VoucherMaster>
{
new VoucherMaster
{
Id = 1,
VoucherDetails = voucherDetails
.Where(x => x.MasterId == 1)
.ToList(),
DateTime = DateTime.Now }
};
Now i need to join MutualFundParameter
with VoucherDetails but that is inside a list of 'Voucher Master'
To join i have tried this but this doesn't work as expected
var res = voucherMasters.Join(
mutualFundParameters,
voucher => voucher.VoucherDetails.FirstOrDefault().AcNo,
mutual => mutual.AcNo,
(voucher, mutual) => new
{
}
);
Thanks Hoping for positive response.
AcNo
isint
inVoucherDetails
, butstring
inMutualFundParameter
? Also, please describe your database relations