0

My STEs work very well and track changes with individual controls like textboxes, memo etc. on the webform, except when used with asp.net gridview. With Gridview on Update it says allways "Added" as state of the STE.

Has anyone a Solution for my Problem?

Martin S.
  • 1
  • 1

2 Answers2

0

Yes because the object being passed to the update method is not queried from the DB, but instantiated. What you can do is attach the entity to the context. This will resolve this issue.

HTH.

Brian Mains
  • 50,520
  • 35
  • 148
  • 257
0

Neither GridView or ObjectDataSource persists entities among requests. When you trigger data modification event on the GridView a new instance of object is created for you. It is not the same entity you used to fill the grid - those instances are lost.

Btw. using STEs in web application and storing entities among requests is probably the worst usage I can ever imagine. Everybody is trying to reduce their memory footprint in web app as well as amount of transferred data between client and server and you are going exactly opposite direction.

Ladislav Mrnka
  • 360,892
  • 59
  • 660
  • 670
  • What problem? You didn't mention any problem. – Ladislav Mrnka Jul 12 '11 at 13:22
  • @Ladislav, unless you're trying to write your code in a way where it will easily be updated to a true service layer using STEs. What you're suggesting is avoiding using STEs, however if you were to layer WCF on top of your business layer and wanted STE functionality then you'd have to go back and rewrite some of your data access where you would have been attaching entities etc. Do you not agree? – e36M3 Jul 12 '11 at 13:28
  • you mentioned using STEs in this context is generally a bad idea. What would you use instead? – Martin S. Jul 12 '11 at 13:29
  • @Martin: I would use POCOs - you create entity from the request and either pass it as updated or a new one. – Ladislav Mrnka Jul 12 '11 at 13:32
  • @e36M3: Yes I'm suggesting [avoiding STEs](http://stackoverflow.com/questions/3814706/self-tracking-entities-vs-poco-entities/3815968#3815968). I believe WCF is out of the scope of this question and even if not, STEs are still something [you should consider twice](http://stackoverflow.com/questions/6642390/is-it-recommended-to-use-self-tracking-entities-with-wcf-services/6647636#6647636) before you use it. Especially you don't need them if you are not working with entity graphs where you need to track changes in relations. – Ladislav Mrnka Jul 12 '11 at 13:38
  • Would you Give me an example using POCOs? In My Application I have a Data Layer in which the EntityModel is, a project in which the STEs are, a service Layer with buissines logic and The view Layer in ASP.net which communicates to the service layer by using wcf. – Martin S. Jul 13 '11 at 04:49
  • What example are you looking for? Simply read something about using POCOs and working with detached objects and ask question targeting a problem (you can be pretty sure that almost every question you want to ask was answered here multiple times). – Ladislav Mrnka Jul 13 '11 at 07:31