.NET

Store-Generated values with Entity Framework

If you are using Entity Framework and you want your data store to generate some values automatically (e.g., to automatically fill a CreateDate with the date and time that the object was created), you should configure the field as Store-Generated. It’s a property on the field in the EDM designer. Read more…

By kryptx, ago
.NET

Guaranteed Deadlock

There was a thread on StackOverflow recently about an interview question where the candidate was asked to write a program that will always deadlock. Eric Lippert’s example is shorter than mine, but I think my answer (which I’m posting here because the question is labeled as a Java question) is Read more…

By kryptx, ago
.NET

Connected Layer, a little deeper

If you're working frequently with the connected layer, the previous post would be sufficient for most purposes (given adequate knowledge of SQL), if perhaps a little awkward. The following information might make your life a little bit easier. (more…)

By kryptx, ago
.NET

ADO.NET – Connected layer basics

In order to send queries to the database, you need an instance of a DbCommand-derived type. This instance is obtained from invoking the CreateCommand method on an instance of DbProviderFactory for the database provider in question, e.g.: 1 2 3 DbProviderFactory df = DbProviderFactories.GetFactory("System.Data.SqlClient"); DbCommand cmd = df.CreateCommand();DbProviderFactory df = Read more…

By kryptx, ago
.NET

Comparing reference types

When comparing two instances of a reference type for equality (in value, not checking to see if they are the same instance), rather than using .Equals it’s best to use an IComparer. In a generic type, if nothing is known about the parameterized types, EqualityComparer<T>.Generic is a good choice.

By kryptx, ago
.NET

WPF Basics

There are three types of controls in WPF. Content controls contain (host) a single nested element in its Content property. The child element can also contain sub-elements of its own. Button, Label, and TextBox are common examples of content controls. Labels and buttons also support mnemonic keys and access keys, Read more…

By kryptx, ago
.NET

Threading notes

One of the simplest ways to create a thread is to use a delegate’s BeginInvoke() and EndInvoke() methods. The only tricky part about this approach is calling EndInvoke() inside of the AsyncCallback delegate method, because the original delegate is out of scope. You can obtain it from the AsyncDelegate property Read more…

By kryptx, ago
.NET

CIL

CIL is the "mother tongue" of .NET, and the only language understood by the CLR. It is also the only language that allows access to all features offered by the CTS. C# in particular, for example, does not support global-level members. Were these ever necessary or useful, they would have to be created in CIL. (more…)

By kryptx, ago
.NET

Delegates

Finally getting to some interesting stuff! When defining a delegate, behind the scenes the compiler creates a sealed class which derives from System.MulticastDelegate. The class has three public methods: Invoke() invokes each method synchronously. This function need not be called explicitly. BeginInvoke() and EndInvoke() allow you to call the method Read more…

By kryptx, ago
.NET

Object Lifetime and the Garbage Collector

The golden rule of .NET memory management is simple:

Allocate a class instance onto the managed heap using the new keyword and forget about it.
The garbage collector destroys an object when it is no longer needed, which is (basically) when the object is unreachable by the code base. (more…)

By kryptx, ago