Home » Tag Archives: C#

Tag Archives: C#

Implementing Inheritance with Entity Framework Code First

1. Introduction This walkthrough is an introduction to implementing inheritance with Entity Framework, Code First approach. A simple strategy for mapping database tables might be “one table for every persistent class”. This approach sounds simple enough and, indeed, works very well until I encountered inheritance. The requirement I was tasked with was simple, develop and implement a database for books. In ...

Read More »

C# Settings reminder

As a reminder to self: Settings are nice (too bad they advertise them as Windows Forms Application Settings, as they are just as useful for other assemblies), but be aware… When using Settings.Default, it will get the values to the state of the app.config (or defaults if there is no app.config) of the assembly that defined the settings, not the ...

Read More »

C#: Lazy is not constrained to static contexts, instance field initializers are: via Stack Overflow

Lazy<T> is not constrained to static contexts. Instance field initialisers cannot use instance references (but can use static references) as they run outside of the constructor.Though there are arguments for instance field initializers too., I think this is a good reason to initialize fields inside the constructor: there you do have access to instance references (but should not call virtual ...

Read More »

Using arrays to speed up static tree traversal

Over the last two weeks I wrote about how to construct and query a string prefix-trie. We used the data structure to quickly find all strings with a given prefix, and to find the longest common prefix in that list. Today we will take a look at how we can use arrays to improve performance even further. We will also ...

Read More »

Critique this code : The memory mapped file

We got an error in the following code, in production. We are trying hard to make sure that we have good errors, which allows us to troubleshoot things easily. In this case, the code… wasn’t very helpful about it. Why? Take a look at the code, I’ll explain why below…   public CodecIndexInput(FileInfo file, Func<Stream, Stream> applyCodecs) { try { ...

Read More »

LINQ Extensions 3 – Batch into sub-sequences

After last weeks post on extracting elements out of a list by minimum or maximum keys Ody Mbegbu mentioned on Google+ how he feels that something LINQ is missing is the functionality to batch, page, or divide a sequence into sub-sequences of a given size. That is what we are going to look at today! In fact, Ody already posted ...

Read More »

LINQ Extensions 2: Minimum/Maximum by key

Last week we talked about LINQ, its usefulness, and how to write our own methods to make it even more powerful. Today, I want to look at another couple methods that I have found handy in a number of different situations. We will look at how to extract the maximum or minimum element of a list by a given key ...

Read More »

The Test Scope Creep

In “Should I use multiple asserts” we described the problem when using them in a single test. In the example I gave, while checking the result of a single operation, it still made sense to get information on both ends of the transaction. Debugging can unravel the issue, yet two separate test results shorten the way to the fix. We are ...

Read More »

Should I use or split multiple asserts?

I get this question often. It makes sense to stuff all kinds of assertions after a single setup and invocation. For me, it usually comes down to: Try to separate rather than join them. While it’s possible to have some asserts for the same operation, in most situations, where we’re better off separating them. The main idea behind this is that if the first ...

Read More »