Note that there are some explanatory texts on larger screens.

plurals
  1. POASP.Net MVC & Entity Framework project architecture WITHOUT repository pattern
    text
    copied!<p>I'm starting a new small project with ASP.NET MVC and Entity Framework. (SQL Server - around 20 DB tables) In past projects I’ve used Linq2SQL but it seems to be obsolete.</p> <p>I've read a lot of posts on using repository pattern for EF (pros and cons) , For me it seems better/simpler to code without repository pattern.</p> <p>I created the following project architecture :</p> <pre><code>namespace MySite.Models { public class User { public Int32 ID { get; set; } public String Email { get; set; } public String Password { get; set; } public String Name { get; set; } public Int32 Gender { get; set; } } } namespace MySite.DAL { public class Users { public static IEnumerable&lt;User&gt; GetUsers() { using (var context = new DatingSiteContext()) { return context.Users.ToList(); } } public static User GetUserByID(int id) { using (var context = new DatingSiteContext()) { return context.Users.Find(id); } } } namespace MySite.Controllers { public class HomeController : Controller { public ActionResult Index() { ViewBag.Message = "Modify this template to jump-start your ASP.NET MVC application."; var users = DAL.Users.GetUsers(); return View(users); } } } </code></pre> <ul> <li>What are the disadvantage of using EF like this? (Except lack of unit testing support) </li> <li>Is it wrong to create a new DbContext on each call to DAL ? Any Performance hit? </li> <li>Any other recommended structure for using EF ? Examples? :)</li> <li>Would you use Linq2SQL in a new project ?</li> </ul> <p>Thank you.</p> <p>Edit:</p> <p>The code inside GetUsers() and GetUserByID() is just for example , i understand its a bad practice to return all records from the db (paging or filter in missing)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload