The EntitySpaces Community

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

add column to already loaded entity

Last post 04-07-2008, 4:21 PM by sklett. 6 replies.
Sort Posts: Previous Next
  •  04-07-2008, 2:11 AM 8741

    add column to already loaded entity

    I really hope this is possible Stick out tongue

    I have loaded a collection of entities and have omitted a single column.  I lazy load this missing column when it is requested.

    I now have a need where I need to update this column on an entity.  It would take a long time to explain *why* I don't just detach, reload the full entity, update and attach but suffice it to say it's not attractive in my setup.  So, as you can imagine I can't assign anything to this column because it's missing (wasn't included in the original query) - what I would like to know is if it's possible to ADD the column to the underlying DataTable and if so what the support method is.

    (fingers crossed) 

  •  04-07-2008, 5:42 AM 8742 in reply to 8741

    Re: add column to already loaded entity

    In the "olden" days, when BLOBs and CLOBs were a real issue, we used to intentionally de-normalize a database, and put the large object in its own table with a one-to-one relationship. Then you could use the hierarchical property to lazy-load and save it. Is that a possibility?
    David Neal Parsons
    www.entityspaces.net
  •  04-07-2008, 5:56 AM 8743 in reply to 8742

    Re: add column to already loaded entity

    The Table is protected so you can certainly add columns to it, I'm in Florida right now on vacation and don't have access to be able to show you an example. Adding a column to the Table.Columns collection is easy however. This would be a good one for our FAQ section. I'll have to work up a sample but it's going to be at least a week.
    EntitySpaces | Twitter | BLOG | Please honor our Software License
  •  04-07-2008, 6:56 AM 8747 in reply to 8743

    Re: add column to already loaded entity

    With this in the Northwind Employees custom collection class:

    Code:
    public void AddNotesColumn()
    {
        if (this.Table != null &&
          this.Table.Columns.Contains("Notes") == false)
        {
            this.Table.Columns.Add("Notes", typeof(System.String));
        }
    }

    Usage:

    Code:
    EmployeesCollection collection = new EmployeesCollection();
    
    collection.Query.Select(
        collection.Query.EmployeeID,
        collection.Query.LastName,
        collection.Query.FirstName);
    
    collection.Query.Load();
    collection.AddNotesColumn();
    
    Employees emp = collection.AddNew();
    emp.LastName = "Test";
    emp.FirstName = "Test1";
    emp.Notes = "Some notes.";
    
    collection.Save();

    David Neal Parsons
    www.entityspaces.net
  •  04-07-2008, 4:17 PM 8764 in reply to 8742

    Re: add column to already loaded entity

    Jeeze, you're making me feel out of it and low tech!  Crying

    I do the same, I have a "FileAsset" table that handles 90% of BLOBS, but this guy is an exception.  So, while I could move this to a new table it would be a decent amount of work.

    I'm curious, when you say "when it was a real issue" - was network performance the issue?  What has changed that it's not as much of an issue any longer?
     

  •  04-07-2008, 4:20 PM 8765 in reply to 8747

    Re: add column to already loaded entity

    David.Parsons:

    With this in the Northwind Employees custom collection class:

    Code:
    public void AddNotesColumn()
    {
    if (this.Table != null &&
    this.Table.Columns.Contains("Notes") == false)
    {
    this.Table.Columns.Add("Notes", typeof(System.String));
    }
    }

    Usage:

    Code:
    EmployeesCollection collection = new EmployeesCollection();

    collection.Query.Select(
    collection.Query.EmployeeID,
    collection.Query.LastName,
    collection.Query.FirstName);

    collection.Query.Load();
    collection.AddNotesColumn();

    Employees emp = collection.AddNew();
    emp.LastName = "Test";
    emp.FirstName = "Test1";
    emp.Notes = "Some notes.";

    collection.Save();

     

    Sweet, this is just what I need, thanks David.

    One question;  when I implemented the above I found that my Table property was null.  The entity in question is part of a collection, so I then tried this.Row.Table and found a valid Table reference.  Is this to be expected when working with an entity that is part of a collection?

    If so, why not have a reference to the Table anyways?  In other words, why not have this.Table -> this.Row.Table?  It would make my code simpler as the method in question deals with entities that may or may not be in a collection so I need to check for Table == null or Row.Table == null.

    Either way, I'm up and running and that's great!  Thanks again,

    Steve 

  •  04-07-2008, 4:21 PM 8766 in reply to 8743

    Re: add column to already loaded entity

    Mike.Griffin:
    The Table is protected so you can certainly add columns to it, I'm in Florida right now on vacation and don't have access to be able to show you an example. Adding a column to the Table.Columns collection is easy however. This would be a good one for our FAQ section. I'll have to work up a sample but it's going to be at least a week.

    Enjoy your vacation, good ol' Dave solved the problem as always! 

View as RSS news feed in XML