Solved

Persistence ignorance?

Posted on 2011-03-25
7
452 Views
Last Modified: 2012-05-11
Please define it if possible is a few sentences. I can not find a link that does it without a very long start to the answer.

I work in the MVC3 ASP.NET 4.0 world.

Thanks,
newbieweb
0
Comment
Question by:newbieweb
  • 3
  • 3
7 Comments
 
LVL 1

Expert Comment

by:jesusaflores
ID: 35217503
what the problemA??, i don't understand...
0
 
LVL 16

Assisted Solution

by:ToddBeaulieu
ToddBeaulieu earned 500 total points
ID: 35217506
I'm not sure what the context is for your question, but persistence describes how your data is stored. A beginner coder might fetch data directly from the controller with queries that are specific to the storage, whether it's SQL, XML, etc. By using the repository pattern, you'd introduce a persistance specific repository that knows about the data implementation (SQL, XML, etc.) and hide that detail from the calling controller (or better yet, a service that is called by the controller).
0
 

Author Comment

by:newbieweb
ID: 35217572
I use a Data Dtore around my Entity Framework 4.0 object. I also have my Controller create a new instance on creation then each Controller Action passes that Data Store into each object that's created, and passed in as a parameter to the nth degree, as a parameter in contruction of my classes.

Is this Persistence Ignorance?

I am trying to get my definition of the tem down.

Thanks.
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 16

Accepted Solution

by:
ToddBeaulieu earned 500 total points
ID: 35217614
I haven't worked with EF, but if you've got the controllers passing EF objects, then it is most certainly NOT persistence ignorant. The controller should not know anything about how data is manipulated. It should call a service, asking for an entity or a collection of entities. The service would then call the correct repository, in the case EF. You might first develop that app with an XML repository and then convert over to an EF repository. If you had coded the EF specific logic into the controllers, then you'd have to rewrite theme ach time you wanted to switch. The mentioned solution would allow you to hand one or the other repository over to the service, asking it to perform the operation. You can also look into "dependency injection", which MVC 3 supports. You tell the service to accept a repository by way of an interface and then configure a special class to return the appropriate repository when it sees any object looking for an IMyRepository.
0
 

Author Comment

by:newbieweb
ID: 35217809
Interesting. I think you're right. I made it persitence aware.

I did this since saving a Project object to a different instance than the one from which is was called created problems.  I actually have a code change that I could keep, even if I were to remove any Controller awareness of the Data Store.

What I do is:
1) Instantiate a Data Store
2) Retrieve a Project from it
3) Set the Data Store property on the Project
4) When I save that Project, it uses the Data Store which spawned it

Is this logical?

Otherwise, EF makes you go throgh hoops to update an existing object.

0
 
LVL 16

Assisted Solution

by:ToddBeaulieu
ToddBeaulieu earned 500 total points
ID: 35217996
Hmmm . Like I said, I haven't used EF yet, but I'll take a stab.

What's a project in your context? An entity?

I really can't believe EF would want you to return EF specific objects to the controller, embedded in the entities.

I'd expect you to have a service that is handed the entity and asked to save it. The service would then forward the request to the EF repository.

Big guess here .. not sure what the DataStore is, but could it be static, meaning it persists across calls, handling all data operations?
0
 

Author Closing Comment

by:newbieweb
ID: 35218036
Sorry for the confusion. A Project is just an object based on the project class. Thanks.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now