The EntitySpaces Community

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

cannot fill an entity property unless the property was part of the original select statement

Last post 08-28-2008, 7:27 PM by Mike.Griffin. 1 replies.
Sort Posts: Previous Next
  •  08-28-2008, 5:40 PM 11024

    cannot fill an entity property unless the property was part of the original select statement

    I have a 'save' function on my webform that will update an entity which has a byte array property for blob objects.  Everything works fine if I select all entity properties and then saving using this code:

     

    Code:
    Certification c = new Certification();

    c.LoadByPrimaryKey(Convert.ToInt32(ViewState["cId"]));

    //fill other properties here

    byte[] bytes = new byte[RadUpload1.UploadedFiles[0].InputStream.Length];
    RadUpload1.UploadedFiles[0].InputStream.Read(bytes, 0, Convert.ToInt32(RadUpload1.UploadedFiles[0].InputStream.Length));

    c.File = bytes;

    c.Save();

    There is no reason to load the blob from the database if it isn't going to change or if I'm just going to overwrite that property and send the bytes back to the database.  What I'd like to be able to do is this:

     

    Code:
    Certification c = new Certification();

    //load all properties except the blob
    esQueryItem qi = new esQueryItem(c.Query, CertificationMetadata.ColumnNames.File, esSystemType.ByteArray);
    c.Query.SelectAllExcept(qi).Where(c.Query.Id == Convert.ToInt32(ViewState["cId"]));
    c.Query.Load();

    //fill other properties here

    byte[] bytes = new byte[RadUpload1.UploadedFiles[0].InputStream.Length];
    RadUpload1.UploadedFiles[0].InputStream.Read(bytes, 0, Convert.ToInt32(RadUpload1.UploadedFiles[0].InputStream.Length));

    c.File = bytes;

    c.Save();

     

    Unfortunately, when I try to assign 'bytes' to 'c.File' using my preferred method of using the 'SelectAllExcept' method, the property remains null and does not save.

     

    Am I doing something wrong or is this just not possible for some reason.

     

    Thanks is advance,

    Paul

  •  08-28-2008, 7:27 PM 11025 in reply to 11024

    Re: cannot fill an entity property unless the property was part of the original select statement

    Okay, first we need to rewrite that query. I'm not sure where you got that sample from Surprise as you should never have create esQueryItems like that, take a look at this:

     

    Code:
    Certification c = new Certification();

    //load all properties except the blob
    c.Query.SelectAllExcept(c.Query.File).Where(c.Query.Id == Convert.ToInt32(ViewState["cId"]));
    c.Query.Load();

    That's they way you want to write queries Yes

    Now, as to the problem. The reason why it is failing is you didn't select the "File" column so when you go to access it there is no "File" DataColumn in the underlying DataTable. In 2+ years no one has ever ran into this.

    You might try this though .... I used the Employees object from Northwind, it has a photo field, here I create the DataColumn if not present. This code is in my "Custom" class and I overload the Photo property.

     

    Code:
    namespace BusinessObjects
    {
    public partial class Employees : esEmployees
    {
    public override byte[] Photo
    {
    get
    {
    return base.Photo;
    }
    set
    {
    if (this.Row != null)
    {
    DataTable dt = this.Row.Table;

    // If the DataColumn isn't present
    if (!dt.Columns.Contains(EmployeesMetadata.ColumnNames.Photo))
    {
    // Create it
    esColumnMetadata esCol =
    this.es.Meta.Columns.FindByColumnName(EmployeesMetadata.ColumnNames.Photo);

    dt.Columns.Add(esCol.Name, esCol.Type);
    }
    }

    base.Photo = value;
    }
    }
    }
    }
    I realize that isn't optimal, but we will add a support method called CreateColumn() that you can call that will force create a column if not present. 

     

     


    EntitySpaces | Twitter | BLOG | Please honor our Software License
View as RSS news feed in XML