Solved

Persistence ignorance?

Posted on 2011-03-25
7
459 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB.NET - Error - Object not set in Module 4 35
Need to learn more about SecurityProtocolType.Tls12 3 32
C# Gridview 1 34
bound data table problem 2 11
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!
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

825 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