ASP.NET 4 General DiscussionFor ASP.NET 4 discussions not relating to a specific Wrox book
Welcome to the p2p.wrox.com Forums.
You are currently viewing the ASP.NET 4 General Discussion section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
I am a little confused about the ASP.Net web form and the presentation layer.
The .aspx file is considered part of the presentation layer because it contains all the layout and formatting. But what about the Code Behind? This can contain business logic such as validations and other rules. What layer is the Code Behind part of?
That's one of the problems with web forms and code behind. It could be anything depending on the code you write. If you use
myControl.BackgroundColor = Color.Blue;
it's the presentation layer. If you calculate a discount based on the number of items the customer has in his cart, it's business logic. If you set up a SqlConnection object and access the database, it's the data access layer.
In general, you should strive to write as little code in Code Behind and instead delegate to the appropriate layer. This way, the Code Behind becomes more of an orchestrator / controller as in MVC.
I just finished reading the chapter 14 and am surprised at how powerful the ADO.Net Entity Framework is and how easy it is to create presentation pages.
I was wondering how the ADO.Net Entity Framework fits in with n-layer architecture?
Where would you put business logic specific to the photo album or picture entities. For ex, there is logic on p. 519 that creates a new file name for the uploaded picture and determines the virtual location. Would I need to create 2 separate business objects and create two classes to represent the Picture and Photo album?
It depends on how you want to implement it. You could use the EF classes Picture and PhotoAlbum as your business entities and extend them (using partial classes) with additional functionality. However, that still ties them closely to the Entity Framework and thus to the database.
A common solution for this is to use EF Code First where you define your model classes first, and let EF handle database interaction. You then create repositories to handle stuff like getting items and updating them.
Google for EF Code First to learn a lot more.
I am working on an article series on N-Layered design using EF Code First. ETA: Unknown ;-)