Practical .NET


Set HtmlHelpers Parameters Using Anonymous Objects in ASP.NET

If you're passing an anonymous object to an HtmlHelper method (to ActionLink, for example), you might want to consider using that anonymous object to eliminate one of the other parameters.

Efficiently Loading Related Objects in Entity Framework

If you're not using the Entity Framework DbCollectionEntry object when working with an entity class's related objects, then your application is running too slow. Using DbCollectionEntry lets you asynchronously retrieve related objects and get only the objects you want.

Customize Browser Window Size When Debugging ASP.NET Apps

If, after pressing F5, you've ever found yourself adjusting the size of your browser window, then this tip is for you. But you shouldn't be surprised if it doesn't work.

Mimic Lazy Loading with Entity Framework 6 and Entity Framework Core 1.1

Entity Framework Core doesn't have lazy loading (at least, not yet). But you can fake it by using explicit loading, though it doesn't work quite the way you might want. In fact, it's probably a good idea to use this in Entity Framework 6.

Selecting Groups in LINQ

Some questions can only be answered by organizing your data into groups and then finding groups that contain particular members or have particular properties.

Grouping Results in LINQ

Complex queries can be solved with a combination of simpler LINQ queries, anonymous objects and the Group/By/Into clauses. Using Group/By/Into will also give you the best possible performance for those complex queries.

Export Your ASP.NET Configuration To Reduce Restarts, Share Settings

You don't have to keep all your configuration settings in your config file. There are even some benefits to exporting sections to separate files.

Returning Raw JSON Data in Web API with Marten

Here's a trick to have Marten automatically deserialize JSON data only when you want it to.

Getting All the Results When Joining with LINQ

When you want to find all the objects that are missing a corresponding object, then you need the LINQ equivalent of an outer join. Here, step by painful step, is how to build that query.

Move from Tab to Tab in the Visual Studio Toolbox Without the Mouse

You don't need to take your hands off the keyboard to move to another tab in the Toolbox.

Working with Enumerated Values in Entity Framework

If you decide on using an Enum with enumerated values in your Entity Framework class, here are the tools you'll need to make it work. But an enumerated value shouldn't be your first choice.

Shortcuts for Defining Anonymous Objects in C# and VB

Here are two ways to save some typing when defining anonymous objects. One only works in Visual Basic, though.

Build Your Own ASP.NET Cache with WeakReferences

You want to keep an object around only as long as you have memory available, do ya? Then you need the WeakReference class.

Enforce Referential Integrity Between Documents in Marten

Marten is PostgreSQL-based, so take advantage of relational features where it makes sense. Here's an example.

Dealing with Complexity with DTOs and Command Objects

Peter starts off with a perfectly good solution to a problem but then complicates the problem . . . and ends up moving to a different design pattern. While on that journey he has some best practices around designing Data Transfer Objects.

Subscribe on YouTube