Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Persistence ignorance?

Posted on 2011-03-25
7
Medium Priority
?
476 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 2000 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
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 
LVL 16

Accepted Solution

by:
ToddBeaulieu earned 2000 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 2000 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

916 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