我有一个字符串列表
List<string> lststr = new List<string>() { "1,", "2" };
我需要生成以下
<DbRuleMappings>
<DbRuleMapping dbDetailId="1" ruleMasterId="1" activeFlag="1" />
<DbRuleMapping dbDetailId="1" ruleMasterId="2" activeFlag="1" />
<DbRuleMapping dbDetailId="1" ruleMasterId="3" activeFlag="1" />
<DbRuleMapping dbDetailId="1" ruleMasterId="4" activeFlag="1" />
<DbRuleMapping dbDetailId = "2" ruleMasterId="1" activeFlag="1"/>
<DbRuleMapping dbDetailId = "2" ruleMasterId="2" activeFlag="1"/>
<DbRuleMapping dbDetailId = "2" ruleMasterId="3" activeFlag="1"/>
<DbRuleMapping dbDetailId = "2" ruleMasterId="4" activeFlag="1"/>
</DbRuleMappings>
我的尝试......不工作
List<string> lststr = new List<string>() { "1,", "2" };
XDocument docDBRuleMapping =
new XDocument(
new XElement("DbRuleMappings",
Enumerable.Range(1, 4).Select(x => x)
.Select(i => new XElement("DbRuleMapping",
new XAttribute("dbDetailId", i),
new XAttribute("ruleMasterId", i),
new XAttribute("activeFlag", 1)))));