The SIF® Zone
creating, assimilating, and promoting excellence in SIF® agent development

Using DataRowAdapter

rated by 0 users
Not Answered This post has 0 verified answers | 5 Replies | 3 Followers

Top 50 Contributor
5 Posts
Points 105
MichelleB posted on 02-26-2010 9:15

Hi,

I am having a problem with mapping.  I can't get the inbound data into a DataRow.  Once MapInbound() returns, there's still no data in dr.  Code:

//---Use the Mappings class to translate the objects received

 

Mappings m = m_fCfg.Mappings.GetMappings("Default");

 

SchoolTableAdapter sta = new SchoolTableAdapter();

 

SchoolInfo sdo;

 

Guid gRefId;

 

DFISIFDataSet.SchoolDataTable dt;

 

DFISIFDataSet.SchoolRow dr;

 

 

while(data.Available)

{

sdo = (

SchoolInfo)data.ReadDataObject();

gRefId =

new Guid(sdo.RefId);

dt = sta.GetDataByRefID(gRefId);

 

if (dt.Rows.Count == 0) //---need to create the record and initialize GUIDS

{

dr = (

DFISIFDataSet.SchoolRow)dt.NewRow();

dr.SchoolRefID = gRefId;

dt.Rows.Add(dr);

}

 

else

dr = (

DFISIFDataSet.SchoolRow)dt.Rows[0];

 

DataRowAdaptor drma = new DataRowAdaptor(dr);

m.MapInbound( sdo, drma );

dr.SIF_MessageID = smi.MsgId;

 

try

{

sta.Update(dt);

}

 

catch(System.Exception ex)

{

 

Error_LogTableAdapter elta = new Error_LogTableAdapter();

elta.Insert(ex.Message,

new Guid(smi.MsgId), DateTime.Now);

}

I have verified that the data is in sdo in the debugger and it appears that the XML file is being parsed fine.  Here's my mapping for this object:

            <!-- ============================== -->

            <!--  Mappings for SchoolInfo       -->

            <!-- ============================== -->

            <object object="SchoolInfo">

               <field name="SchoolName">SchoolName</field>

               <field name="SiteID">LocalId</field>

     

            </object>

It is not confined to this one object, none of them are working.  What am I missing???

Also, when I do get this working… I noticed while reading the docs that it seems if there is data already present in the DataRow, it will not replace it with whatever was sent in the SIF object…. For example, say it is a SchoolInfo object sent to change the name of a school.  If I send a DataRow that contains the old name, then it will not get updated?  If that is the case, to update an existing record, I’d have to get all the new data in a DataRow and then “combine” it with the existing information?

Thanks in advance,

Michelle

  • | Post Points: 45

All Replies

Top 10 Contributor
46 Posts
Points 1,180

Hi Michelle,

I'm trying to dissect the code here to understand it better. There is one thing that I noticed. In the documentation for the DataRowAdaptor class, it mentions:

To use this class, create an instance of it, based around a DataRow instance. If you 
are navigating a DataTable, you are responsible for setting the <see cref="SourceRow"/> property    
as you are navigating through the table for either in inbound or outbound mapping

It might be worth giving that a try first to see if that helps. Then we can tackle the next issue(s) that comes up.

Regards,

Jared

  • | Post Points: 25
Top 50 Contributor
5 Posts
Points 105

Well, I saw that but assumed passing it in the constructor took care of that...  Actually, I verified it in the debugger, that the sourcerow was indeed set to my dr.  But I tried it anyway and it made no difference.

Michelle

  • | Post Points: 25
Top 10 Contributor
46 Posts
Points 1,180

Hi Michelle,

We're digging through our example agent archives to see if we've got one that would be a useful reference for you. I will let you know as soon as we find it.

 

-Jared

  • | Post Points: 5
Top 10 Contributor
215 Posts
Points 5,055

Michelle,

In my investigation of this, it appears to me that the DataRowAdapter in the ADK does not currently allow the DataRow to be updated with values from SIF. The reason for this is because the ADK mappings engine by default does not overwrite values in any FieldAdaptor. This is something we should implement support for to enable the scenario that you are demonstrating above.

For now, I'm wondering if you can look at the GenericDataSubscriber example agent that ships with the .NET ADK? That example uses a class called "DataMappings" that does have support for overwriting values in a DataTable. Try that. Let me know if it doesn't work for you.

Andrew Elmhorst
Chief Architect
Edustructures 

  • | Post Points: 25
Top 50 Contributor
5 Posts
Points 105

Andrew,

Took me a few minutes, but I see what's going on now.... I added a DataMappings object to my project and it did not recognize it... I moused over it in the GenericDataSubscriber and it said it was in the using Edustructures.SifWorks.Tools.Mapping but no luck in my project!  Then I noticed it was a class added to GenericSubscriber, lol... thought I had lost my mind for a minute!  But I remember looking at that class in the beginning and the comment about DataRowAdaptor.  Since DataRowAdaptor was implemented in the ADK, I assumed it was an old comment and that it was functioning.  That's what assuming gets you.  I'll add that class to my project and go from there.  I think it will be fine.

Thanks for your quick responses!

Michelle

  • | Post Points: 5
Page 1 of 1 (6 items) | RSS
Copyright ©2006-2009 sifzone.com
Sponsored by Edustructures
We Connect the Systems that Power Education
 
SIF and Schools Interoperability Framework are trademarks of the Schools Interoperability Framework Association.