Batch processing with Entity Framework .NET

Entity Framework is a built-in ORM in .NET. It’s great to work with. It handles the complete data access for you. (Connection, query generating, executing of SQL commands etc.) The performance is OK, if you don’t work with lot of data. The current release (.NET 4.0) doesn’t support batch processing. That means: If you add… Read More »

Aspect-oriented programming (AOP) with Spring.NET

The motivation of aspect-oriented programming is to separate program logic. Application can be devided in two concerns. 1. Core: Contains the program/business logic like calculation etc. 2. System: Contains system specific processes like logging. In this example, I show you how to implement a AOP based logger. Logging is something you need very often. But… Read More »

C# COM interop and optional parameters

Since C# supports optional paramters it is much easier to work with COM objects. Sometimes you don’t want to set every parameter when you call a method from a COM object. Let’s take the “Office Word” object for this easy example. The following C# 3.5 code creates a Office Word object and opens the document… Read More »

Creating CLR Stored Procedures

It’s possible to run .NET code inside a Stored Procedure. How it works: First create a new “Visual C# SQL CLR Database Project”. (There is a same template for VB.NET. But who uses VB nowadays??? :)) You have to define the connection to your database. If you are using Visual Studio 2010 be sure to… Read More »

How to debug .NET Libraries in COM Environment

It is really easy to debug COM registered .NET libraries. The only thing you have to do is calling the “Debug.Assert();” method in the .NET code. See the code: [ComVisible(true)] public class Lib { public string HelloWorld() { Debug.Assert(false, “Debug!”); return “hello world”; } } When you call the method for instance from a VBScript… Read More »

Named and Optional Parameters in C#

You may know the Optional and Named Parameters from other programming languages. C# supports this functionality since version 4.0. In the example below you see how you can define Optional Parameters (see signature of “RegisterUser”) and how you can call this method. class Program { static void Main(string[] args) { // normal call Program.RegisterUser(“fname1”, “fname1”,… Read More »

.NET 4.0 dynamic Data Type

Microsoft implemented some nice dynamic features in .NET 4.0. For instance the new data type “dynamic”. Loading dynamically Libraries with .NET < 4.0 reflection can be tricky. In the following example you see how it works. (Well, there are multiple possibilities for this..) Assembly asbMath = Assembly.LoadFrom(“Lib.dll”); object objMath = asbMath.CreateInstance(“Lib.Math”); Type tMath = asbMath.GetType(“Lib.Math”);… Read More »

File download mit .NET

Es gibt zwei Varianten Files vom Internet zu kopieren. Hier die einfachere Variante: Die Methode “DownloadFile” holt sich das File und speichert es lokal ab. string strUrlPicture = “http://www.yoururlhere.abc/logo.gif”; WebClient client = new WebClient(); client.DownloadFile(strUrlPicture, @”C:\logo.gif”); client.Dispose(); Die zweite Variante erlaubt etwas mehr Kontrolle. Das File wird zuerst in ein byte-Array geladen. string strUrlPicture =… Read More »