开发者

Entity Framework Self-Tracking and Client not tracking changes

How come my client isnt tracking changes. My code below

Server WCF with selftracking entities enabled

 public class TrialService : ITrialService
{

        public Project GetProjectByID(int _projectId)
    {
        var db = new TrialEntitiesService.FringeNETEntities();

        return db.Projects.Include("Items.SubItems").First(s => s.ProjectID == _projectId);
    }

    public Item UpdateItem(Item _item)
    {
        var db = new TrialEntitiesService.FringeNETEntities();

        _item.Actual = 100000;
        db.Items.ApplyChanges(_item);
        db.SaveChanges();
        return _item;
    }



}

and client

    public MainWindow()
    {
        InitializeComponent();
        using (TrialServiceClient proxy = new TrialServiceClient())
        {

            radGridView1.ItemsSource = proxy.GetProjectByID(37).Items;
            return;
        }
    }

    private void button1_Click(obj开发者_StackOverflowect sender, RoutedEventArgs e)
    {
        using (TrialServiceClient proxy = new TrialServiceClient())
        {

            proxy.UpdateItem((Item)radGridView1.SelectedItem);

        }
    }
}

I was assuming that the item in the first call would also be updated. isn't this what Self-Tracking entities achieves or am I missing the big picutre.

If this isn't want Self-Tracking Entites is for then how would i best acheive this rather then manually find and modify the item from the first server call.


When using STEs you cannot simply Add service reference to the service. You must first add reference to the assembly containing STEs and make sure that types from that assembly are reused during adding service reference. Otherwise your client gets new implementation of entities which don't contain self tracking functionality. Two walkthroughs:

  • Using Self Tracking Entity to retrieve and update
  • Walkthrough: Serialize Self-Tracking Entities
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜