2

Using VS2010, C#, Winforms and Entity Framework 4.1

Here is my code

var order = dbContext.Orders.Where(o=>o.OrderId == 1).Single();
var orderDetails = order.OrderDetails.ToList():

textBox1.Bindings.Add("Text", order, "OrderAmount");
gridView.DataSource = orderDetails;

I have following two questions about Entity Framework 4.1

  1. If I update an entity property, the new value is not reflected to the UI.

  2. I want to add logic to an entity property setter; but it gets rewritten each time the model is updated.

Thanks.

Surjit Samra
  • 4,614
  • 1
  • 26
  • 36
user1104916
  • 103
  • 1
  • 11
  • My Winforms knowledge is poor. But I think you should check some refreshing properties of your visual component (as I understood a new record appeared in the database). – Alex Kovanev Dec 18 '11 at 22:29

2 Answers2

0

About the second question.
Automatic updating of classes is how the model first works.
You can read EF 4.1 Code-first vs Model/Database-first for more information.

Sometimes it's convenient to modify the T4 template. But I don't recommend to change getters/setters. Instead adding some dataannotations attributes could be useful. You can read how to use it on MSDN:
Using Data Annotations to Customize Data Classes
How to: Validate Model Data Using DataAnnotations Attributes

Community
  • 1
  • 1
Alex Kovanev
  • 1,858
  • 1
  • 16
  • 29
0

use the on property change inside of the databinding

textBox1.DataBindings.Add("Text",order,"OrderAmount",true,System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged);