The EntitySpaces Community

Share and learn about the EntitySpaces Architecture.
Welcome to The EntitySpaces Community Sign in | Join | Help
in
Home Forums Photos

Filling an EsCollection out of an ordinary DataTable

Last post 10-04-2007, 8:13 AM by paschoal1. 11 replies.
Sort Posts: Previous Next
  •  10-03-2007, 9:19 AM 5525

    Filling an EsCollection out of an ordinary DataTable

    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;

     

    }

  •  10-03-2007, 10:13 AM 5528 in reply to 5525

    Re: Filling an EsCollection out of an ordinary DataTable

    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
  •  10-03-2007, 10:22 AM 5529 in reply to 5525

    Re: Filling an EsCollection out of an ordinary DataTable

    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
  •  10-03-2007, 11:31 AM 5533 in reply to 5525

    Re: Filling an EsCollection out of an ordinary DataTable

    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!
  •  10-03-2007, 1:42 PM 5538 in reply to 5533

    Re: Filling an EsCollection out of an ordinary DataTable

    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
  •  10-03-2007, 2:36 PM 5545 in reply to 5538

    Re: Filling an EsCollection out of an ordinary DataTable

    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?
  •  10-03-2007, 5:02 PM 5555 in reply to 5545

    Re: Filling an EsCollection out of an ordinary DataTable

    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
  •  10-04-2007, 5:44 AM 5564 in reply to 5555

    Re: Filling an EsCollection out of an ordinary DataTable

    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...

  •  10-04-2007, 6:12 AM 5571 in reply to 5564

    Re: Filling an EsCollection out of an ordinary DataTable

    Don't use esDataSource, simply bind your GridView to a datatable.
    EntitySpaces | Twitter | BLOG | Please honor our Software License
  •  10-04-2007, 6:22 AM 5572 in reply to 5571

    Re: Filling an EsCollection out of an ordinary DataTable

    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

  •  10-04-2007, 6:37 AM 5574 in reply to 5572

    Re: Filling an EsCollection out of an ordinary DataTable

    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
  •  10-04-2007, 8:13 AM 5580 in reply to 5572

    Re: Filling an EsCollection out of an ordinary DataTable

    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!

View as RSS news feed in XML