How i add relations from list<t>
Hey,
i have add some DataSources from a list<t>
how can i add some relations between bak and angebotlst
it works on preview but i at runtime the fielt from the relation cant found.
var bak = tarifcontext.Bauartklasse.ToList();
var report = new Report();
report.Load(Path.Combine(reportsFolder, "Antrag.frx"));
report.AutoFillDataSet = true;
report.RegisterData(bak, "Bauartklasse");
report.RegisterData(angebotlst, "Angebot");
This discussion has been closed.
Comments
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using FastReport.Data;
namespace FastReport
{
public class BusinessObject1
{
public int id {get; set;}
public string parentname {get; set;}
}
public class BusinessObject2
{
public int id {get; set;}
public string childname {get; set;}
}
public class ReportScript
{
private void _StartReport(object sender, EventArgs e)
{
List<BusinessObject1> list1 = new List<BusinessObject1>();
list1.Add(new BusinessObject1 { id = 1, parentname = "A" });
list1.Add(new BusinessObject1 { id = 2, parentname = "B" });
list1.Add(new BusinessObject1 { id = 3, parentname = "C" });
List<BusinessObject2> list2 = new List<BusinessObject2>();
list2.Add(new BusinessObject2 { id = 1, childname = "A1" });
list2.Add(new BusinessObject2 { id = 2, childname = "B1" });
list2.Add(new BusinessObject2 { id = 3, childname = "C1" });
list2.Add(new BusinessObject2 { id = 1, childname = "A2" });
list2.Add(new BusinessObject2 { id = 2, childname = "B2" });
list2.Add(new BusinessObject2 { id = 3, childname = "C2" });
Report.RegisterData(list1, "Table1");
Report.RegisterData(list2, "Table2");
Relation relation = new Relation()
{
Name = "Table1_Table2",
ParentDataSource = Report.GetDataSource("Table1"),
ChildDataSource = Report.GetDataSource("Table2"),
ParentColumns = new string[] { "id" },
ChildColumns = new string[] { "id" },
Enabled = true
};
Report.Dictionary.Relations.Add(relation);
Data1.DataSource = Report.GetDataSource("Table2");
Data1.Sort.Add(new Sort("[Table2.childname]", false));
Text1.Text = "[Table2.Table1.parentname]";
Text2.Text = "[Table2.childname]";
}
}
}
Hello!
When using `RegisterData(List<T>, ...)`, relationships between two independent lists (`bak` and `angebotlst`) are not automatically created based on foreign keys (unlike a `DataSet` with `DataRelation`). What worked in the designer preview with a test data source must be explicitly declared in `report. Dictionary.Relations (if not saved in .frx) and include:
report.RegisterData(bak, “bak”, 2); report.RegisterData(angebote, “angebotlst”, 2); var dsBak = report.GetDataSource(“bak”); var dsAng = report.GetDataSource(“angebotlst”); dsBak.Enabled = true; dsAng.Enabled = true; var rel = new FastReport.Data.Relation { Name = “bak_angebotlst”, ParentDataSource = dsBak, ChildDataSource = dsAng, ParentColumns = new[] { “Id” }, ChildColumns = new[] { “BakId” }, Enabled = true }; report.Dictionary.Relations.Add(rel); detailBand.Relation = rel;