Entity Framework: Why not use Bindingsource.AddNew for creating new objects...

Assuming that you have a Detail Form with a Bindingsource, and the Bindingsource has as Datasource a IQueryable or something derived from that.

image BAD

If you use the Bindingsource to create new objects like this:
your record is detached, and your business rules fire on Save (probably to late for Winforms)

image BETTER

      bindingSource.DataSource = Business.AddNewObject(); 
Your record is attached, and business rules fire OnChange

Assuming you have a Business method like this.

      public Patients AddNewObject()
          MyObject p = new MyObject ();
          // SetDefaultValues(p);
          return p;

Latest Posts

Popular Posts