Page 1 of 1

Does bindingsource work with Entity model?

Posted: Tue 17 Aug 2010 09:50
by kerrywales
I have Devart build 152. I develop in Vs 2008 & DevExpress extensions.
I am using the DevExpress Xtrareport feature

Please bare with me for the scenario.

I can use the following construct to link the devart produced model to the report
//I use NoRows to restrict the data returned when providing the report writer with the model structure
//There is a small number when testing the report
//It is then the number of rows in the table for the full report
var query = (from client in ReportDataConnection.TblClientHead
select client).Take(noRows);
xrDesignPanel1.Report.DataSource = query1;

The report shows the model centered around my table and it has the data from the main table (TblClientHead) but the data from the linked tables is not auto loaded.

I read that BindingSource has a CurrentChanged event which can have code to load the linked tables as the record of the main table changes.

This gives me the procedure
private void bs_CurrentChanged(object sender, EventArgs e)
{
BindingSource bs = ((BindingSource)sender);
var c = ((TblClientHead)bs.Current);
c.TblJobsHeads.Load();
}

Seems sensible. But now to the crucial line.

I need to link a BindingSource object to the dataset produced in the query. I have been told to use the construct

BindingSource bs = (BindingSource)xrDesignPanel1.Report.DataSource;

But this produces the error
{"Unable to cast object of type 'System.Data.Objects.ObjectQuery`1[KF.Jobs.Model.TblClientHead]' to type 'System.Windows.Forms.BindingSource'."}

This implies that the Devart produced dataobject is not compatible with BindingSource or I am misunderstanding this, new to me, syntax and grammar.

If someone can point me in the right direction I would be most greatful.

Regards :?:

Posted: Tue 17 Aug 2010 12:42
by AndreyR
Try the following code instead:

Code: Select all

BindingSource bs;
bs.DataSource = (BindingSource)xrDesignPanel1.Report.DataSource;

Posted: Tue 17 Aug 2010 13:06
by kerrywales
Thank you for the suggestion. I did try and vary from the sample source and use:

BindingSource bs = new BindingSource();
bs.DataSource = (BindingSource)xrDesignPanel1.Report.DataSource;

I get the same error.

Posted: Tue 17 Aug 2010 13:34
by AndreyR
Sorry, a misprint.

Code: Select all

BindingSource bs = new BindingSource(); 
bs.DataSource = xrDesignPanel1.Report.DataSource;

Posted: Tue 17 Aug 2010 13:39
by kerrywales
Your reply got me thinking I have got non error code in:

var query = (from client in ReportDataConnection.TblClientHead
select new {client}).Take(noRows);
xrDesignPanel1.Report.DataSource = query1;
BindingSource bs = new BindingSource(xrDesignPanel1.Report.DataSource, "client");
bs.CurrentChanged += new EventHandler(bs_CurrentChanged);

but bs_CurrentChanged is never called.
I presume because the query dataset "client" does not change.

This makes me think that I need to bind bs to a column in the query dataset which changes as I go through the dataset.

One such column in the "client" dataset is "Reference" but I cannot work out the binding syntax.

I have tried
BindingSource(xrDesignPanel1.Report.DataSource, "Reference");
and
BindingSource(xrDesignPanel1.Report.DataSource, "client.Reference");

both of which fail.

Does anyone know if I can create a bindsource object to a column within a query result?

Regards

Posted: Wed 18 Aug 2010 12:57
by AndreyR
Could you please send us a small test project illustrating the problem?
Maybe we will be able to help you.
Send it to support * devart * com, subject "EF, XtraReport, BindingSource". Please include the script of your DB objects to your e-mail.

Posted: Sat 21 Aug 2010 08:22
by kerrywales
I am going to leave it for a while. I am looking at costs to update to VS 2010 so that I can use .NET 4 and learn about the DATALOADOPTIONS etc to see if that resolves it. (as I do not have access to it with 2008).

I did try :
var q1 = (from X1...
from X2...
from X3...
select new
{
X1,
X2,
X3
}).Take(noRows);
var query1 = (q1.AsEnumerable().Select(c => c.X1)).ToList();
try
{
bs.DataSource = query1;
xrDesignPanel1.Report.DataSource = bs.DataSource;
}

This works great with one-to-one, having peculior results with one-to-many but doesn't work for many-to-many.

The good thing with this is that query1 returns a single object with all the related data included.

Also starting to readup about views as a possible alternative for simpler restricted views.

Posted: Sat 21 Aug 2010 14:08
by StanislavK
dotConnect for PostgreSQL and Entity Developer support Entity Framework 4.0, hence all features available in standard EF 4 models should be available in Devart entity models. Please tell us if you encounter any problems with this.

Could you please describe the issues with many-to-many and one-to-many associations in more details? If possible, please specify the definitions of tables used and the queries with which the problem can be reproduced.

Posted: Tue 31 Aug 2010 07:53
by kerrywales
I had more than one issue that meant I opened up more than one forum question.
But they are merging into one.

The example of one-to-many not returning the expected results fo VS 2008 + .NET 4 is in thread

http://www.devart.com/forums/viewtopic. ... 0388#60388

In essence I only get the first record returned.

Thanks

Posted: Wed 01 Sep 2010 16:12
by AndreyR
I have replied to you in this thread.