THIS DOES NOT WORK ON UPDATES. Can someone help.
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;
namespace Destination
{
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();
}
}
}