THESE FORUMS ARE NOW FROZEN
Please choose "Forums" from the Main menu of www.entityspaces.net to get to our new forums.

Filling an EsCollection out of an ordinary DataTable

rated by 0 users
This post has 11 Replies | 1 Follower

Top 10 Contributor
Posts 478
paschoal1 Posted: 10-03-2007 9:19 AM

How could I fill an esCollection from a datatable previously created and loaded? I tried the code below, but it didnt work...Raises me a compilation error. 

protected void EsDataSource6_esSelect(object sender, EntitySpaces.Web.esDataSourceSelectEventArgs e)

{

DataTable d = new DataTable();

d.Columns.Add( new DataColumn("id", typeof(String)));

d.Columns.Add(new DataColumn("Name", typeof(String)));

DataRow dataRow = d.NewRow();

dataRow["id"] = "1";

dataRow["Name"] = "Teste";

 

e.Collection = d;

 

}

Top 10 Contributor
Posts 3,881

When posting code use our "Code" button rather than copying code in from visual studio.  Also, why are you doing this when you can load a collection from the database using any low level method in the base class? If you are getting the data that is in this DataTable from the database then you can definitely load it into your collection through one of the protected Load() methods.

That code just doesn't make sense? The esDataSource doesn't work with raw datatables and that entire set of code can be done on your Collection via AddNew() and simply filling in the properties?

EntitySpaces | Twitter | BLOG | Please honor our Software License

Top 10 Contributor
Posts 3,881

This is alot easier and far less error prone than messing with DataTables ...

Code:
protected void EsDataSource6_esSelect(object sender, EntitySpaces.Web.esDataSourceSelectEventArgs e)
{
    EmployeeCollection coll = new EmployeeCollection();
    Employee emp = coll.AddNew();
	
    emp.FirstName = "Mike";

    e.Collection = coll;
}

 

EntitySpaces | Twitter | BLOG | Please honor our Software License

Top 10 Contributor
Posts 478
I think you didnt understand what I need. I dont need to get data from a escollection. I need to feed my escollection from a datatable (or a hashtable, either one is good), that I will add by hand!
Top 10 Contributor
Posts 3,881
Sure, but you just create the EntitySpaces collection and feed it into that, that was my point? There is more complicated stuff that happens underneath, like creating entities based on rows and stuff. Nothing wrong with having your own data, but it's easy to feed that into an EntitySpaces collection.

EntitySpaces | Twitter | BLOG | Please honor our Software License

Top 10 Contributor
Posts 478
well, sorry for insisting in such a point, but i seem to be still stuck in this issue...so, how can I "load" a datatable (or hastable) into an esCollection?
Top 10 Contributor
Posts 3,881

This might work, however, EntitySpaces is not meant to be used in this fashion, so we cannot spend a lot of cycles on technical support regarding this issue. Officially, this is not supported. This method would go in your Custom class.

 

Code:
public partial class CustomerCollection : esCustomerCollection
{
public bool CustomPopulate()
{
DataTable dt = SomeMethodThatReturnsADatatable();

this.Table = dt;
this.PopulateCollection();
}
}

The reason we cannot spend a lot of time on this is because the end result is the same as if you would have populated the entity from the public EntitySpaces API. I'm bewildered as to why you want to use this approach? There is also a method called CreateColumnsForBinding() which will create the underlying DataTable for an Entity, but again, I'm confused on your approach. 

EntitySpaces | Twitter | BLOG | Please honor our Software License

Top 10 Contributor
Posts 478

I give up...I just cant use any of the existing collections for doing this job. I wanted a simple taks, that is, fill a datatable into a escollection (not a custom or a generated collection that was created by MyGeneratio). If I need this, it is for some reason....

Thanks anyway...

Top 10 Contributor
Posts 3,881
Don't use esDataSource, simply bind your GridView to a datatable.

EntitySpaces | Twitter | BLOG | Please honor our Software License

Top 10 Contributor
Posts 762

Hi

If I'm understanding the question properly I think what is being asked is the following

1) You've created your own class based off esEntityCollection - i.e. this class is manually crafted and has not been generated by MyGeneration so you have an empty class that inherits from esEntityCollection,.

2) You want to fill this collection from a datatable or other source.  As the class doesn't include the regular generated entityspaces code you're trying to do this with methods that are defined and implemented in esEntityCollection.

Unfortunately I don't have time to look into this personally but I thought it might help to rephrase the question (if I've understood it correctly) so that someone else may better answer it.

Hope that helps but apologies if I've completely misunderstood

Cheers

Martin

Top 10 Contributor
Posts 3,881
There is just no hope in getting that to work. It seems all this is just to use esDataSource, it's very easy to bind without esDataSource as well.

EntitySpaces | Twitter | BLOG | Please honor our Software License

Top 10 Contributor
Posts 478

Perfect Martin, now you understood what I meant. Its exactly this, I just needed to use a simple esCollection (the basic one that is there when we provide the esDataSource), feeding it from a datatable. I understand you ES fellows are overcharged on tasks and improvements. Again, sorry for interrupting this, I found a workaround anyway...

Thanks!

Page 1 of 1 (12 items) | RSS
Copyright © 2005 - 2009, EntitySpaces, LLC