我有一个通用列表
LinkedList<RelationModel> mylist = new LinkedList<RelationModel>();
此列表获取两个索引{0}和{1}的输出。两个索引都有多个值。调试时,
{0} - the output is
Foreign "Store" --string
ForeignKeyColumn "addressId" --string
Primary "Address" --string
PrimaryKeyColumn "addressId" --string
{1} - the output is
Foreign "Address" --string
ForeignKeyColumn "countryId" --string
Primary "Country" --string
PrimaryKeyColumn "countryId" --string
问题是我必须从列表中选择不同的值。例如-在这里,商店,地址和国家/地区是不同的。如何在C#代码中选择这些值?
以下代码将数据填充到我的列表中
using (var ctx = new TestDBEntities())
{
var foreginKeyList = ctx.Database
.SqlQuery<MetdataModel>(" Select [PKTABLE_NAME], [PKCOLUMN_NAME],[FKTABLE_NAME],[FKCOLUMN_NAME] from GetMetadata")
.ToList();
LinkedList<RelationModel> mylist = new LinkedList<RelationModel>();
for (int i =0; i < foreginKeyList.Count; i++)
{
var ss = foreginKeyList.Where(p => p.FKTABLE_NAME.Equals(foreginKeyList[i].FKTABLE_NAME)).Select(p => new { p.PKTABLE_NAME, p.PKCOLUMN_NAME }).ToList();
foreach(var col in ss)
{
RelationModel gg = new RelationModel();
gg.Foreign = foreginKeyList[i].FKTABLE_NAME;
gg.ForeignKeyColumn = foreginKeyList[i].FKCOLUMN_NAME;
gg.Primary = col.PKTABLE_NAME;
gg.PrimaryKeyColumn = col.PKCOLUMN_NAME;
mylist.AddLast(gg);
}
}
我需要一个最终列表,该列表将具有不同的值,例如
mylist.[0]- store
mylist.[1]- address
mylist.[2]- country
答案 0 :(得分:0)
假设Foo
是
Foo
然后您可以使用以下内容:
RelationModel
现在您可以访问public class RelationModel {
public string Foriegn;
public string ForeignKeyColumn;
public string Primary;
public string PrimaryKeyColumn;
}
,var ans = mylist.SelectMany(m => new[] { m.Foriegn, m.Primary }).Distinct().ToList();
等ans
的元素。