Data Access Application Block for .NET 4.5 using MVC 4 - asp.net

I'm trying to develop an application using MVC 4.
Earlier I was using Generic repository for accessing my database .
But later I was suggested to use Data Access Application Block to access Data Base in my application .
I'm not getting any exact clue that how to start with it.
Can any one suggest some link which can provide me the exact information about Data Access Application blocks for .NET 4.5 and MVC 4 and also some examples of its correct usage.
Thanks in Advance..

I think Data Access Application Block is quite obsolete.
Why don't you use an ORM (such as Entity Framework or NHibernate) to build your data access layer? As you can see here Entity Framework is Microsoft’s recommended data access technology for new applications

There's quite a lot of documentation on the Pattern & Practices site at MSDN, http://msdn.microsoft.com/en-us/library/dn440726(v=pandp.60).aspx.
I have used DAAB in a few projects, but it's quite heavyweight and isn't as widely used as other frameworks. It's also very data-centric rather than being more domain oriented. You might want to consider Entity Framework or a similar ORM over DAAB.

Related

Configure database for MVC authentication

I've been Googling terms like
configure database for mvc authentication
But I can't find anything from this decade that relates to my configuration.
I've created an MVC application using .NET Framework 4.6 with authentication support (database first). Now where do I find step-by-step instructions for creating the database tables and configuring MVC to use them?
Thanks for any tips!
The correct thing to google for is 'ASP.NET Identity'.
If you generate an MVC app straight from one of the templates it will generate a number of classes to handle security and identity.
One of these classes will implement interface IUserStore. The class provided will inherit from Microsoft.AspNet.Identity.EntityFramework.UserStore<TUser>, and uses Entity Framework to check the database if the tables exist, and create them if they are not there.
If you are uneasy about giving your application enough privileges to modify your data schema (ew!), you can create your own class that implements IUserStore and plug that into the system.
It's a big topic, but hopefully this is enough to get started with.

Entity Framework Vs Data Access Layer

I want to know list of advantages of using Entity framework over data access layer.
My website is host in shared hosting and i don't have access to IIS
Considering that i am working shared hosting world, is it feasible to work with entity framework?
Microsoft has publicly stated that Entity Framework will be the preffered data access technology for the .NET platform. Given your experience I feel like Entity Framework would be a huge asset to your ability to rapidly develop applications. Shared hosting is completely irrelevant to the fact that you are using entity framework. Just make sure that the hosting company supports .Net 4 framework (or w/e framework version you work with).
Entity Framework is a data access layer. Specifically it's an Object Relational Mapper.
So it basically comes down to - do you want to write your own DAL? - or would you rather spend your time building out the Data Model, and then having Entity create your entities and classes, etc.. for you.

Using RIA Services directly within an ASP.NET MVC 2.0 project

I am starting a new project which will need a ASP.NET MVC 2.0 website, a Silverlight section and a Windows Phone 7 UI.
My plan was to use WCF RIA Services to create a set of services which would be used in all different UI projects. With the Silverlight project I would use the standard tool integration, the Windows Phone looks like it may have to be WCF Services exposed by the RIA Domain Services, but I'm not sure about the ASP.NET MVC website.
My initial thoughts I would simple reference the class library containing the Domain Services and use them directly. Could this be considered a viable approach to using RIA Domain Services in a ASP.NET MVC website?
Kind Regards
Michael
I know a long time has passed since this question was asked, but since I had to make such a decision, I might as well document it for the benefit of others.
I work in an environment where lots of legacy and new apps co-exist, with the legacy apps being phased out. So we've had to build interoperability between everything from MS Access, to web service end points in C#, VB, Web Forms, MVC 3, even Flex, Reporting Services...the list goes on.
One of the biggest pain points in a multiple-client scenario is the maintenance of interoperability over time. As data, requirements and delivery mechanisms change, keeping things smooth ends up taking a lot of resources.
My approach has been to create one and only one mechanism for reading a given source of data by defining 1) a model, 2) a serialization/deserialization layer and 3) a service layer. All projects that need to use XY_Data must use the XY_Service to get XY_Objects via the XY_Serializer. Direct db calls or stored procs, etc are allowed in the XY_Application. This allows me to drop in replacement DLLs (versioned) with bug fixes and upgrades without restarting anything. I hardly ever do a full publish.
So yes, what you're suggesting will work. I would recommend only that you rigorously enforce the single-source-of-truth and DRY policies both in your data and your APIs.

Sharing a common DAL between WPF, Silverlight, and ASP.NET

What is the best method/technology to sharing the same data access layer between WPF, Silverlight, and ASP.NET?
I am using ADO.NET Entity framework, and was thinking of a creating a DAL using the Repository pattern.Then using the RIA Services as a dummy middle man to connect Silverlight and ASP.NET. Is this a solid plan or are there other better solutions out there?
One of the solutions I like to use is the following :
- Have a project storing only the entities (for example : Player, Game, Entity) with no reference to the database at all.
- Have a project implementing the repository pattern (Repository, Repository etc...)
- Use ADO.NET Entity Framework code first approach to map with the database (it creates a dynamic child object of your entities contain in your project, see ScottGu's blog for an explanation on how to use it)
Connecting Silverlight to your pattern can be done with Ria Services or classic WCF services. Usually I try to use WCF whenever possible as Ria Services is not really compliant with an MVVM development.
If you want to use WCF and share your DAL entities with Silverlight you can create a MyDal.Silverlight Silverlight class library project and add symbolic link instead of copies of every entities you will want to share with Silverlight. Then when you'll add a service reference with visual studio it will be smart enough to not create copies off Player, Game and User to you Silverlight project.
If you want to use Ria Services it will create copies of you entities anyway.
Hope that helps
John
RIA Services
RIA services will certainly take the burden off you for all the WCF plumbing. It has a few minor flaws (lack of certain data types), but there are workarounds for most problems.
The validation model (using attribute decoration and custom validators) is very strong and a great place to hang business rules.
RIA coexists happily with ASP.Net, so that is another plus. Behind the scenes it is just another WCF service. We are happily using RIA services with MVVM and Prism.
ADO.Net EF model
This is a tried and tested feature rich model. The only problems I have found related to many-to-many relationships. Again there are workarounds.
DAL
As RIA change sets are managed for you on anything, including POCO, this is the area that will need the most attention. It is considered "bad" to expose your EF model directly to RIA and that will certainly not insulate you from data changes.
I can't specifically recommend any one pattern yet (still experimenting), but make sure your choice is compatible with IQueryable. The paging feature and appending to Linq queries for server-side execution are features you do not want to lose!

Asp.net MVC Question regarding n-tier

I have studied a lot of starter kits for ASP.NET and ASP.NET MVC really is awesome compared to web forms, because it runs fast and developement is easy. But when I fit ASP.NET MVC, LINQ in a site with a lot of visitors and mostly controls based website, I got so many issues in my mind.
Let's say I want to build a website which is small scale, but got a lot of visitors and mostly controls based (i.e. TV Show Information website). You've got shows, episodes.
Is it efficient and easy when you use n-tier architecture in ASP.NET MVC?
Should I create my own entities in Business Logic Layer or use SQL Tables as entities?
Should I use Application Cache in it to save all shows in cache?
I like the Presentation Layer of MVC using LINQ but when it comes to DataAccess and BusinessLogic its confusing me. Can anyone help?
My 2 cents:
In my opinion there is no difference between using ASP.Net MVC or Web Forms in an N-Tier architecture. We use WCF to comunicate between tiers.
We create Data Transfer Objects that are not the Entity Framework Entities. However, I expect this to change with the next version of Entity Framework which introduces POCO.
Not sure what you mean by "shows". ASP.Net has its own caching for pages, for caching data you could use Enterprise Library.
Just to clarify I define a Tier as a separate machine, where as a layer would be a separate dll.
i've just read an amazing article regarding working n-tier with asp.net mvc
check it out:
http://www.codeproject.com/KB/aspnet/ASP_NET_MVC_WITH_EF.aspx
it's all about right architecture working with ASP.NET MVC Framework + N-tier + Entity Framework
enjoy!
:-Dan
I highly recommend the NerdDinner ASP.NET MVC Tutorial. You can get more info on it and download the free chapter from ScottGu's blog post here.
In the code that accompanies that sample chapter there is a pretty good architecture structure that you can use to base your architecture on. I have gone back to it several times when trying to see how to architect something in ASP.NET MVC.
Have you built your first application in ASP.NET MVC yet, or are you still studying?
I think you should start with an architecture similar to NerdDinner and refactor after you become more familiar with how ASP.NET MVC works.
If you really are well versed in multi-tier, then you should be able to figure it out without help from us. Try some things. Do what works. Try not to worry so much about being "correct."
Some of what you are asking in your question is premature if you haven't written your first ASP.NET MVC application yet.
By the way, I found Scott Hanselman's "File/New/NerdDinner" video both enlightening and entertaining: http://videos.visitmix.com/MIX09/T49F
I use my own flavor of n-Tier with MVC because I don't like LINQ-to-SQL and the Entity Framework. I've also written some T4 templates that generate those objects and the use the Enterprise Library to interact with the DB. It's up to you, whatever works.

Resources