当我尝试以下 LINQ 过滤器时
var productsInfo = from product in productsElement.Descendants("product").Filter(rule)
from photo in product.Descendants("photo")
from parameter in product.Descendants("parameter")
let id = product.Attribute("id")
let addr = photo.Attribute("addr")
let name = parameter.Attribute("name")
select new { ID = id.Value, Addr = addr.Value, Name = name.Value };
我收到以下错误:
The given ruleset does not contain any rules with type
System.Xml.Linq.XElement, System.Xml.Linq, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089 (Error E106)
我的规则:
<?xml version="1.0" encoding="utf-8"?><codeeffects xmlns="http://codeeffects.com/schemas/rule/41" xmlns:ui="http://codeeffects.com/schemas/ui/4"><rule id="09973a56-3d6a-4616-ae1c-40d0d17e95b9" webrule="4.3.6.7" utc="2017-07-24T10:07:08.6346" type="testSlimWebRule.products, testSlimWebRule, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" eval="true"><definition><condition type="equal"><property name="AllProducts.product.id" /><value type="numeric">1</value></condition></definition><format><lines /></format></rule></codeeffects>
XML:
XDocument productsElement = XDocument.Parse(@"<products>
<AllProducts>
<product id='1'>
<photo addr='1.jpg'/>
<parameter name='name'/>
</product>
<product id='2'>
<photo addr='2.jpg'/>
<parameter name='Kenneth'/>
</product>
</AllProducts>
</products> ");
使用 Visual Studio“插入为 XML 类”生成的产品类:
namespace testSlimWebRule
{
/// <remarks/>
[System.SerializableAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
[System.Xml.Serialization.XmlRootAttribute(Namespace = "", IsNullable = false)]
public partial class products
{
private productsAllProducts allProductsField;
/// <remarks/>
public productsAllProducts AllProducts
{
get
{
return this.allProductsField;
}
set
{
this.allProductsField = value;
}
}
}
/// <remarks/>
[System.SerializableAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
public partial class productsAllProducts
{
private productsAllProductsProduct productField;
/// <remarks/>
public productsAllProductsProduct product
{
get
{
return this.productField;
}
set
{
this.productField = value;
}
}
}
/// <remarks/>
[System.SerializableAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
public partial class productsAllProductsProduct
{
private productsAllProductsProductPhoto photoField;
private productsAllProductsProductParameter parameterField;
private byte idField;
/// <remarks/>
public productsAllProductsProductPhoto photo
{
get
{
return this.photoField;
}
set
{
this.photoField = value;
}
}
/// <remarks/>
public productsAllProductsProductParameter parameter
{
get
{
return this.parameterField;
}
set
{
this.parameterField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public byte id
{
get
{
return this.idField;
}
set
{
this.idField = value;
}
}
}
/// <remarks/>
[System.SerializableAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
public partial class productsAllProductsProductPhoto
{
private string addrField;
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string addr
{
get
{
return this.addrField;
}
set
{
this.addrField = value;
}
}
}
/// <remarks/>
[System.SerializableAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
public partial class productsAllProductsProductParameter
{
private string nameField;
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string name
{
get
{
return this.nameField;
}
set
{
this.nameField = value;
}
}
}
}
ASP.net 部分:
<rule:RuleEditor ID="ruleEditor" runat="server"
Mode="Filter"
ShowToolBar="false"
SourceAssembly="testSlimWebRule"
SourceType="testSlimWebRule.products" />
我尝试了几种设置过滤器的组合,但找不到解决方案。
我错过了什么?