ASP.NET MVC5 Entity Framework and Best Practices (Repository Pattern etc)

I'm hoping to get some guidance here towards implementing best practices in my application and maybe some rock solid resources for reading further.

I can't find a definitive answer, only what looks like opinion to me on whether implementing the repository pattern is indeed a good thing or a bad thing when you are using Entity Framework. It seems to me, based on what I have read about the repository pattern that EF is already an implementation of the repository pattern, which makes me agree with the "unnecessary side".

I can also see the other side of it too, at present I have no unit tests at all in my application, mostly because I'm unsure of how to implement them properly without writing code that messes up the live SQL data.

I can see the benefit of implementing the pattern, and how that deals with CRUD, but then I struggle to see how I would use a repository to represent something complex like this, which exists in one of my controllers:

var endpointConstructor = db.tbl_equipment.Include(t => t.tbl_Backup_Configuration) .Where(e => e.tbl_Backup_Configuration.FirstOrDefault().BackupType == null) .Where(e => e.tbl_customer.Calc_Contract_Status == true && e.Calc_Contract_Status == true && e.Equip_type.Contains("server")).OrderBy(e => e.tbl_customer.Priority) .Select(s => new CompanyServerUserViewModel { Comp_ID = s.Comp_ID, ServerName = s.NetBIOS_name, Company = s.Company, TeamviewerID = s.tbl_computerinfo.FirstOrDefault().teamviewerID } ); 

Not sure how I would even begin testing that. I've only been with C# and ASP.NET for about four months and I feel like I have hit a point where I can code working applications, but the more I read the more I feel my code is messy.

Any advice? I'm open to reading materials, tutorials, anything to help improve on those types of areas!

by TNTGav via /r/csharp

Leave a Reply