c# - Visual Studio 2013 Rdlc - 如何显示导航属性中的值

标签 c# visual-studio-2013 report rdlc

我正在使用 Entity Framework (代码优先)在 Visual Studio 2013 上构建 WPF 应用程序。

我有一个 Order 类,它有一个 Customer 的虚拟属性。

public class Order
{
  public int OrderId { get; set; }
  public DateTime OrderDate { get; set;}
  public virtual Customer Customer { get; set; }
}

public class Customer
{
  public int CustomerId { get; set; }
  public string Name  { get; set; }
  public string DocumentNumber { get; set; }
  public DateTime BirthDate { get; set; }
}

我正在尝试在报告公式上显示客户的姓名。我试过:

=First(Fields!Customer.Value.Name, "MyDataSet")
=First(Fields!Customer.Name.Value, "MyDataSet")

=字段!客户.值.名称
=字段!客户.名称.值

它只是在该字段上显示#Error。订单中的其他字段正确显示。

它有效:

=First(Fields!OrderDate.Value, "MyDataSet")

当我从上下文中检索实体时,我使用 Include 加载了 Customer。所以空引用不是问题。

Order order = context.Orders.Include(o => o.Customer).Where(o => o.OrderID == id).FirstOrDefault();

我搜索了以下内容和其他内容,但听起来似乎仅适用于 Visual Studio 2010 或者只是不起作用:
Bind child object property with in rdlc (Report)
http://wraithnath.blogspot.com.br/2011/04/reportviewer-object-datasource-nested.html

是否有一些事情我没有做,或者我应该以其他方式处理,例如某种“代码优先 View ”?

最佳答案

这个答案在 VS2013 中对我有用:

http://wraithnath.blogspot.com/2011/04/reportviewer-object-datasource-nested.html

确保你的类满足要求,记住添加无参数构造函数,(它只对我有用,直到我添加无参数构造函数)

list :

  • 所有类都是可序列化的(类中的每个用户类型都必须是可序列化的) 可序列化,并且用户类型属性中的任何用户类型都必须是可序列化的 可序列化)
  • 所有类都有一个公共(public)无参数构造函数
  • 报告中使用的所有类都必须具有 public 修饰符
  • 如果数据源的任何属性或属性的任何属性不能 序列化然后你会得到#Error。只要确定一切 可序列化
  • 确保不会出现无限递归问题,例如,A 类有一个 类 B 的属性,并且类 B 具有类 A 的属性。使用 XMLIgnore/ScriptIgnore 属性

这是我的类(class):

[Serializable]
public class Person
{
    public Person()
    {

    }
    public string Name{ get; set; }
    public string Address1{ get; set; }
    public string Id{ get; set; }
    public string Phone { get; set; }
}

父级:

[Serializable]
public class Header
{
    public Header()
    {

    }

    public string Product { get; set; }
    public DateTime EmisionDate{ get; set; }
    public string Number { get; set; }
    public Person Person { get; set; }
}

这就是我的表情

=First(Fields!Person.Value.Name, "dsHeader")

关于c# - Visual Studio 2013 Rdlc - 如何显示导航属性中的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33577425/

相关文章:

c# - 从代码隐藏 (C#) 为 javascript 变量设置值

c# - 如何在 Asp.Net Core 中注册同一接口(interface)的多个实现?

c# - 在字符串中查找匹配的 guid

javascript - Apache Cordova 无法从根目录读取文件

c# - 检查客户端端口是否打开并转发 [C#, ASP.NET]

c# - 编译在某些方法中省略固定 block 后的代码

c++ - 运算符优先级更改

oracle - 增加 oracle reports builder 中的页面宽度

html - 分页前 : always is freezing print dialog box

mysql - 使用 SQL Union 执行依赖于日益宽松的条件的复杂报表查询