This is a migrated thread and some comments may be shown as answers.

Insert not returning Association

1 Answer 42 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Paul
Top achievements
Rank 1
Paul asked on 31 Aug 2011, 03:02 PM
Hi,
    I have 3 tables. and have foriegn key association setup and the classes generated are below. I have created a metadata class so to include the association. Using RIA and in silverlight I can query the Table1tablelink and this pulls back all the records for this entity including the associated Table1 entities which is what I expect. When I insert a new record into the Table1table2link like Mycontext.Table1table2links.Add(new Table1table2link(){Table1_Id=3, Table2_Id =5}); I then submit it and the Table1table2link_Id gets populated with the new correct id but the associated Table1 entity is null. When debugging and looking at the domainservice open access callback function for the insert I can clearly see that the Table1 entity has been properly populated with the correct association but this seems to get lost when returned back to the silverlight app.

Is there something else I need to set to make this return.  

Table1 class looks like this
namespace DA   
{
    public partial class Table1
    {
 
        private int _table1Id;
        public virtual int Table1_id
        {
            get
            {
                return this._table1Id;
            }
            set
            {
                this._table1Id = value;
            }
        }
        private string _name;
        public virtual string Name
        {
            get
            {
                return this._name;
            }
            set
            {
                this._name = value;
            }
        }
        private IList<Table1table2link> _table1table2links = new List<Table1table2link>();
        public virtual IList<Table1table2link> Table1table2links
        {
            get
            {
                return this._table1table2links ;
            }
        }
                    }
}

Table2 class looks like this
namespace DA   
 
{
 
    public partial class Table2
 
    {
 
  
 
        private int _table2Id;
 
        public virtual int Table2_id
 
        {
 
            get
 
            {
 
                return this._table2Id;
 
            }
 
            set
 
            {
 
                this._table2Id = value;
 
            }
 
        }
 
        private string _name;
 
        public virtual string Name
 
        {
 
            get
 
            {
 
                return this._name;
 
            }
 
            set
 
            {
 
                this._name = value;
 
            }
 
        }
 
        private IList<Table1table2link> _table1table2links = new List<Table1table2link>();
 
        public virtual IList<Table1table2link> Table1table2links
 
        {
 
            get
 
            {
 
                return this._table1table2links ;
 
            }
 
        }
 
                    }
 
}

Table1Table2Link class looks like this
namespace DA   
{
    public partial class Table1table2link
    {
        private int _table1Id;
        public virtual int Table1_id
        {
            get
            {
                return this._table1Id;
            }
            set
            {
                this._table1Id = value;
            }
        }
         
        private int _table2Id;
        public virtual int Table2_id
        {
            get
            {
                return this._table2Id;
            }
            set
            {
                this._table2Id = value;
            }
        }
         
        private int _table1table2linkId;
        public virtual int Table1table2link_id
        {
            get
            {
                return this._table1table2linkId;
            }
            set
            {
                this._table1table2linkId= value;
            }
        }
         
        private Table1 _table1;
        public virtual Table1 Table1
        {
            get
            {
                return this._table1;
            }
            set
            {
                this._table1= value;
            }
        }
         
        private Table2 _table2;
        public virtual Table2 Table2
        {
            get
            {
                return this._table2;
            }
            set
            {
                this._table2= value;
            }
        }
         
    }
}

I have a metadata class for Table1table2link
namespace DA
{
    [MetadataTypeAttribute(typeof(Table1table2link.Table1table2linkMetadata))]
    public partial class Table1table2link
    {
        internal sealed class Table1table2linkMetadata
        {
 
            [Include]
            [Association("Table1", "Table1_id", "Table1_id")]
            public Table1 Table1 { get; set; }
  
 
        }
    }
}

Thanks

1 Answer, 1 is accepted

Sort by
0
Zoran
Telerik team
answered on 05 Sep 2011, 03:32 PM
Hello Paul,

 I believe that you have to fetch the Table1 object prior to transferring it to the client side. When you insert a new Table1Table2link object with only the Table1ID set, the Table object is not fetched from the database and that is probably the reason you do not see it transferred on the client side. I believe that if you are able to see that entity in the debugger because when you debug, the debugger is actually accessing the Table1 property and that is when the property is being fetched from the database. Is there a possibility for you to access the Table1 object before it is returned to the Silverlight client? I guess that should be done by the RIA runtime since it is returning the association back when you perform a query. Maybe it is a bug with RIA services not to return it on insert, because if OpenAccess does insert the correct data in the database I do not see any reason that you association is not returned. However we will have a look into our implementation and will give you feedback as soon as we are able to locate the false behavior.

Regards,
Zoran
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's SQL Server Community Awards. We are competing in TWO categories and every vote counts! VOTE for Telerik NOW >>

Tags
General Discussions
Asked by
Paul
Top achievements
Rank 1
Answers by
Zoran
Telerik team
Share this question
or