【问题标题】:Ambiguous match found exception in BindingListView在 BindingListView 中发现模棱两可的匹配异常
【发布时间】:2015-11-25 14:50:44
【问题描述】:

我在使用 Andrew Davey 的 BindingListView (http://blw.sourceforge.net/) 时不断收到此异常。我正在使用 ServiceStack OrmLite 。我的对象如下所示:

public class Category
{
    [PrimaryKey, AutoIncrement]
    public int Id { get; set; }
    [StringLength(50)]
    public string Name { get; set; }
}

public class Product
{
    [PrimaryKey, AutoIncrement]
    public int Id { get; set; }
    [References(typeof(Category))]
    public int CategoryId { get; set; }
    public int ProductTypeId { get; set; }
    [StringLength(50)]
    public string Name { get; set; }

    [Reference]
    public Category Category { get; set; }
}

我不知道如何传递这个异常。

编辑

异常发生在以下代码的第一行:

var products = dbConn.Select<Product>().OrderBy(p => p.Name).ToList();
var productsView = new BindingListView<Product>(products);
dgProducts.DataSource = productsView;

【问题讨论】:

  • 能把出错的代码显示一下吗?
  • 我只是编辑问题并添加了代码。
  • 我在同一页。错误只发生在 AggregateBindingListView.cs 的第 2024 行:return Activator.CreateInstance(viewType, list);
  • 同时我发现了这个问题。我的班级中有一个List&lt;T&gt;,我必须在构造函数中实例化它。之后它就起作用了。

标签: c# reflection data-binding


【解决方案1】:

你有

product.Name
product.Category.Name

product.Id  
product.Category.Id

当该库进行反射以获取属性时,它会获得 2 个“名称”。

代码不知道,你想要哪一个。 Product.Name 来自或 Product.Category.Name。


tldr:简单修复是更改属性名称之一

public class Category
{
    public int cId { get; set; }
    public string cName { get; set; }
}


public class Product
{
    [PrimaryKey, AutoIncrement]
    public int Id { get; set; }
    [References(typeof(Category))]
    public int CategoryId { get; set; }
    public int ProductTypeId { get; set; }
    [StringLength(50)]
    public string Name { get; set; }

    [Reference]
    public Category Category { get; set; }
}

【讨论】:

    猜你喜欢
    • 2022-08-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-13
    • 2014-08-12
    • 1970-01-01
    相关资源
    最近更新 更多