You can first create your IEnumerable and then at the end convert it to Dictionary.
Provided your model is as below,
public class DummyModel
{
private const decimal MinValue = 0m;
public int Id { get; set; }
public string FieldName { get; set; }
public string LabelName { get; set; }
//[DecimalValidatorAttrubute(precision: 2, maxdigits: 2, minValue: decimal.MinValue, maxValue: 99.99m)]
//public decimal Decimal { get; set; }
}
Method below
private Dictionary<string, string> getDictionary()
{
var tbl1 = new List<DummyModel>() { new DummyModel() { Id = 1, FieldName = "Field1", LabelName = "Label1" }, new DummyModel() { FieldName = "Field2", LabelName = "Label2" } };
var tbl2 = new List<DummyModel>() { new DummyModel() { Id = 1, FieldName = "Field3", LabelName = "Label3" }, new DummyModel() { FieldName = "Field4", LabelName = "Label4" } };
var tbl3 = new List<DummyModel>() { new DummyModel() {Id = 1,FieldName = "Field5", LabelName = "Label5" }, new DummyModel() { FieldName = "Field6", LabelName = "Label6" } };
const int cid = 1;
Dictionary<string, string> dict = new Dictionary<string, string>();
dict = tbl1.Where(a => a.Id == cid)
.Concat(tbl2.Where(a => a.Id == cid))
.Concat(tbl3.Where(a => a.Id == cid))
.ToDictionary(a => a.FieldName, a => a.LabelName);
return dict;
}
Would help you to achive something like
[TestMethod]
public void LinqDictionary()
{
var dict = getDictionary();
foreach (var item in dict)
{
Console.WriteLine("FieldName {0}, LabelName {1} ", item.Key, item.Value);
}
}
Output
FieldName Field1, LabelName Label1
FieldName Field3, LabelName Label3
FieldName Field5, LabelName Label5