none
IMultipleResults.GetResult() not populating partial class property RRS feed

  • Question

  • I have a method that uses IMultipleResults.GetResult() to populate a generic List.  The proc I'm calling returns a result that is identical to an existing dbml class, with the addition of an extra joined column (a name).  If I add this column to my dbml class, it works fine.  This ruins my dbml class, however, because that joined column isn't a part of the table.  If I add a partial class with this property on it, it will never get populated from GetResult.

     

    Here is the code:

    Code Snippet

     

    orgData.Containers = multipleResults.GetResult<Container>().ToList();

     

     

     

    Here is my partial Container class:

    Code Snippet

    public partial class Container {

    private string _containerTemplateName;

    public string ContainerTemplateName {

    get { return _containerTemplateName; }

    set { _containerTemplateName = value; }

    }

    }

     

     

    My Container class in the dbml has a ContainerTemplateID, and I'm joining the name from another table.  Once again, I've verified everything works great if I just add ContainerTemplateName to my dbml class - Container.  Can anyone shed any light on why GetResult is refusing to populate my partial class property?

     

    Any help will be appreciated.

     

    Tim

    Wednesday, April 30, 2008 12:03 AM

Answers

  • GetResult won't fill in properties with data unless they are mapped as columns.  If you add a [Column] attribute to ContainerTemplateName it will work.  However, that will leave you in the same situation as when you just added that column to the Container class in the designer.  If the result of the sproc is not really one of your entity types you should not be using the entity to read the data into, you should make up another type (with column attributes of course).

     

    Wednesday, April 30, 2008 4:14 AM
    Moderator

All replies

  • GetResult won't fill in properties with data unless they are mapped as columns.  If you add a [Column] attribute to ContainerTemplateName it will work.  However, that will leave you in the same situation as when you just added that column to the Container class in the designer.  If the result of the sproc is not really one of your entity types you should not be using the entity to read the data into, you should make up another type (with column attributes of course).

     

    Wednesday, April 30, 2008 4:14 AM
    Moderator
  • So, you would recommend making a "temporary" data container - a class with properties containing column attributes that map to the columns being returned by the proc?  Then I can just manually move that data into my original Container class?  Can I use a dynamic type for this (var), or is that not possible because the properties have to have the [Column] attribute?

     

    Thanks for the response, knowing that the [Column] attribute is vital to the mapping is very helpful.

     

    Wednesday, April 30, 2008 3:46 PM
  • I would not use the Container entity class, since this stored proc is returning something different; it has an extra column that the entity does not define.

     

    Friday, May 2, 2008 3:55 PM
    Moderator