|
Architect or Cobbler?
Good code starts with good design |
|
about me
links
Blogs I follow
recent posts
archives
feeds |
Deleting objectsFriday, March 07, 2008Before I start to talk about the Clear method, a little correction to the code I published yesterday. I am effectively obtaining and closing an ObjectContext with each DAO call. This is extremely inefficient, and i probably want to change it in future so that the Context is opened once per thread, but I'm going to leave it as it is for now. It does mean that I should Detach any entities from the ObjectContext before returning them, as an entity keeps a back pointer to it's ObjectContext, and it can't be attached to more than one at a time my DAO would start throwing exceptions the minute you started using it properly. So why is deleting objects so difficult? Essentially it isn't if the object graph is attached and fully built, you issue a DeleteObject and the entity and the relationships are flagged as deleted, any related entities that have Cascade delete rules will also be flagged as deleted(and when you issue SaveChanges the rows will be removed from the underlying store). But in our DAO the objects are being sent to is in a Detached state, which means you have to rebuild the object graph in order for the object to be deleted - If you don't you'll end up with either orphaned records in the database, or you'll throw Constraint exceptions. There are many approaches to building the Object Graph back up, for instance DannySimmons has a blog posting about this. Unfortunately, while Danny's method is cool it doesn't work in a disconnected scenario very well (try to reason why. Here's a big hint, will the ObjectSateManager contain values for detached objects?), or for my scenario, which is to work with any entity (I do have a generic DAO after all). So I know to get hold of the relationship information for any entity, and while I'm sure there may be easier ways i just grabbed the attribute values from the EdmRelationshipAttribute which is added by the EDM generator. This lists all the relationships across all Entity Containers and all Entity Sets, so i need to know which Entity container and Set I'm working with, so I've modified the constructor to pass these in. Once I have the attribute names it's a fairly straightforward matter to test if the entity I'm passing in is involved in the relationship. I was even toying with writing a Linq query, then decided against it ;-)
Now all you have to do is load the related objects into the ObjectContext. If you have these entities, you could simply attach them to the context, and then add them back in to the related end, in my case I went for the expensive option (but always guaranteed to work) of loading the object graph by issuing Load(). Now you can safely delete the object foreach (IRelatedEnd related in re) There is only one problem to solve now, how do I get every object in the EntitySet? I'll leave you with that little puzzle, but think Linq :-) # posted by James @ 12:26 PM # posted by @ 2:26 PM After reading you site, Your site is very useful for me .I bookmarked your site! I am been engaged 10 years on the finance personal software If you have some questions, please get in touch with me. My Home [b][url=http://www.financepersonalsoftware.com/]finance personal software[/url][/b] # posted by @ 6:39 AM [url=http://seghan.ru/go.php?sid=2][img]http://banners.servized.com/current/gif/tam_720x90_1.gif[/img][/url] [url=http://old-drugstore.net/]What is/are Zovirax Tablets?[/url] What are acyclovir tablets or capsules? ACYCLOVIR (Zovirax®) treats certain types of viral infections, specifically herpes infections. Acyclovir will not cure herpes infections; it desire remedy the sores mend faster and expropriate to release the pain or discomfort. Occasionally acyclovir is given to helper avert the infection from coming back. Acyclovir also treats shingles and chickenpox infections. Generic acyclovir tablets and capsules are available. What should I tell my healthiness care provider in front of I be involved this medicine? They prerequisite to differentiate if you be suffering with any of these conditions: •dehydration •neurological infection •kidney murrain •seizures (convulsions) •an unusual or allergic response to acyclovir, ganciclovir, valacyclovir, valganciclovir, other medicines, foods, dyes, or preservatives •expectant or distressing to get in a family way •breast-feeding [url=http://best-drugstore.aoaoaxxx.ru/][img]http://i079.radikal.ru/0910/b9/3f666eb40896.jpg[/img][/url] [url= ]Zovirax without a prescription or doctorpurchase Zovirax uk delivery [/url] buy Zovirax without rxZovirax deliver to uk fed ex overnight [url= ]Zovirax cash deliverybuy Zovirax online cod [/url] Zovirax no script required express deliveryno prescriptions needed for Zovirax [url= ]Zovirax cod saturday delivery fedexZovirax same day delivery [/url] Zovirax online purchaseno prescription Zovirax fedex delivery [url= ]Zovirax online no prescriptionZovirax next day no prescription [/url] Zovirax overnight delivery no rxZovirax no rx fed ex [url= ]Zovirax with codZovirax cheap next day [/url] buy Zovirax saturday deliverysaturday delivery on Zovirax [url= ]Zovirax online doctorspurchase Zovirax cod cash delivery [/url] buy generic Zovirax no prescriptionBuy Zovirax overnight shipping [url= ]Zovirax online overnightorder Zovirax online cod [/url] Zovirax overnight fed exZovirax cheap cod [url= ]Zovirax no prescription cash on deliverybuy Zovirax [/url] cheap Zovirax prescriptionsZovirax with next day delivery without prescription with free shipping [url= ]no perscription Zovirax next daybuy Zovirax online without a prescription and no membership [/url] cheap Zovirax over nightZovirax shipped overnight without a prescription [url= ]Zovirax with no prescriptionZovirax rx [/url] cheap Zovirax next day deliverybuy Zovirax without a prescription overnight shipping # posted by @ 12:06 PM Wow! what an idea ! What a concept ! Beautiful .. Amazing … # posted by @ 2:11 PM great post..., keep up the good work! debt solution # posted by debt solution @ 8:08 PM Post a Comment << Main blog page |
|
|
|