3 Answers, 1 is accepted
Please find attached demo project and SQL script.
The SQL script contains the schema of a *source* Database including some demo data. The solution also uses a *destination* database which is exactly the same as the source one, with the exception of having any data in it. The solution takes all the records from the source and inserts it into the destination. Objects are transferred using AutoMapper.
Please bear in mind that you will have to update the reference of AutoMapper.dll.
If the above example does not help you solve the problem, please send us a sample project (your automapper configuration will be necessary), so we can look into it.
Nikola
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

Looked at the solution at it only seems to work for inserts NOT updates. I changed the code to do updates as follows but .GetUpdates() returns 0:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AutoMapper;
using SourceLibrary;
{
class Program
{
private static void InitializeMapper()
{
Mapper.CreateMap<
SourceLibrary.ORDER
, ORDER>();
}
static void Main(string[] args)
{
InitializeMapper();
using (DestinationDBContext destinationDBContext = new DestinationDBContext())
{
////clear the destination tables
//foreach( ORDER destinationOrder in destinationDBContext.ORDERs )
//{
// destinationDBContext.Delete( destinationOrder );
//}
//destinationDBContext.SaveChanges();
Console.WriteLine( "Destination orders count == " + destinationDBContext.ORDERs.Count() );
using (SourceDBContext dbContext = new SourceDBContext())
{
IList<
SourceLibrary.ORDER
> orders = dbContext.ORDERs.ToList();
foreach (SourceLibrary.ORDER sourceOrder in orders)
{
ORDER orderDestination = destinationDBContext.ORDERs.FirstOrDefault(r => r.ORDER_ID == sourceOrder
.ORDER_ID);
orderDestination = Mapper.Map<
SourceLibrary.ORDER
, ORDER>(sourceOrder);
destinationDBContext.SaveChanges();
//Add(orderDestination);
}
}
Console.WriteLine( "Updated orders = " + destinationDBContext.GetChanges().GetUpdates<
ORDER
>().Count );
destinationDBContext.SaveChanges();
// Console.WriteLine( "Destination orders count after insert == " + destinationDBContext.ORDERs.Count() );
}
Console.ReadLine();
}
}
}
In order for the GetUpdates api to work correctly you will need to make changes to an object that is already tracked by our context. In your case the changes you are making are done on objects that are not being tracked by the context and thus you are not getting any result from the method.
Kind regards,Petar
the Telerik team