Web serivce imports data and stores in business logic Graph.AddressList
. If match found, add to keepList
.
Problem is the data is exactly the same but it is not being added to the keep list. For example ENTITYKEY in record in database is populated but not in the Xml without writing out every column in the database to match every column in the xmlRecord. Is there a way around this?
// Fetch List Of Addresses
List<Address> updateAddressList = DbContext.GraphAddressList.Where<Address>(p => p.PersonnelNo == action.PersonnelNo).ToList<Address>();
////IF ADDRESS EXISTS IN THE DB, BUT NOT IN THE XML FILE, REMOVE FROM DB
List<Address> keepList = new List<Address>();
foreach (Address recordInDB in updateAddressList)
{
foreach (Address_0006 recordInXML in Graph.AddressList)
{
if (recordInDB == recordInXML)
{
keepList.Add(recordInDB);
}
}
}
List<Address> removeList = updateAddressList.Except(keepList).ToList();
foreach (Address record in removeList)
{
DbContext.AddressList.DeleteObject(record);
}
Thanks for reply so really I need to do create a class
public override bool Equals(object obj)
{
var item = obj as RecommendationDTO;
if (item == null)
{
return false;
}
return this.RecommendationId.Equals(item.RecommendationId);
}
public override int GetHashCode()
{
return this.RecommendationId.GetHashCode();
}