Category: <span>EntityFramework</span>

Encapsulating Query Logic in MVC Apps Without the Repository Pattern

One of the most common questions I get when people see a video or presentation about how I build MVC applications is, “Why don’t you use the repository pattern?”  There are a lot of reasons not to use the repository pattern, and they’ve been well-covered by others.  But, one valid benefit they provide is encapsulation…

Read More

Returning Multiple Result Sets from a Stored Procedure Using Entity Framework 6

I know, I know, you’re already rolling your eyes!  “Stored procedures??!?”  But hey, sometimes a stored procedure is the best solution to a problem!  Entity Framework allows you to call stored procedures quite easily out of the box, but working with sprocs that return multiple result sets isn’t so easy.  Here’s a handy extension method…

Read More

Entity Framework, Enums, and TINYINT

Entity Framework supports Enum properties on your model, but there’s one little gotcha that’s bitten me on more than one occasion now.  In your database, you may be tempted to save space by configuring the backing column to use an integer value that takes up less space than a normal int, such as a TINYINT…

Read More

Random Link Roundup–9/19/2014

It’s Friday, which means another round-up of useful links.  Oh, and a cat picture! [more] There’s some really cool stuff coming with C# 6.0.  Check out some of the enhancements! Be sure to check out EntityFramework.Extended if you are using Entity Framework.  It adds support for future queries, caching, and auditing to EF. Want to…

Read More

Random Link Roundup

Happy Friday!  Here are some random, useful links I have come across over the last couple of weeks.  [more] If you follow the standard of using ViewBag.Title to set page titles in ASP.NET MVC, you have probably run into an annoying problem that occurs when you combine Editor Templates with view models that contain a…

Read More

Making TransactionScope Work with async/await in .NET 4.5

I ran into a frustrating little problem today.  I’m getting started with Entity Framework 6 and its async features on a new project, and my SpecsFor integration tests were bombing out unexpectedly.  In turns out the problem was caused by TransactionScope and async work together out of the box.  Or rather, how they don’t work…

Read More

A Generic Entity Framework 5 Repository With Eager-Loading

I’ve been doing some work with Entity Framework 5 lately.  Here’s a simple generic repository I created that allows you to “Include” related entities by applying an attribute. [more] Consider these sample entities: public class User { [Key] public int UserId { get; set; } [Required, MaxLength(50)] public string Username { get; set; } [Required]…

Read More