Browse by Tags

All Tags » .Net » C# (RSS)

dynamic and indexer

Remember one year ago, I wrote a post on how to use reflection with dynamic keyword . At this moment, I sent an email to MS to add an indexer in dynamic. I don’t know if my email changed any thing but I am very happy to see that from .NET 4.0 Beta 2,...
Posted by Matthieu MEZIL | with no comments
Filed under: ,

PFx is good

I am sure that the Parallel Framework (PFx) will take more and more importance in future developments. However, demos often are not in phase with the reality. It’s true that a fractal demo on a 1000 cores machine is ideal for parallel demo, however in...

How to get the typed instance in the abstract class?

Alex James , PM on EF, publish sometimes some C# posts . He published a post to explain how to “link” the methods call . To realize it, he returns the instance in his methods: public abstract class PropertyConfiguration { private bool _nullable;...
Posted by Matthieu MEZIL | with no comments
Filed under: ,

How to have FK in EF v1?

Before answering this question, I will start with another one: why do we need FK? to be able to change a relationship without loading the related entity but we can already do it with the EntityReference property. for the binding With the windows forms...
Posted by Matthieu MEZIL | with no comments

POCO: CreateObject and object initializer

When we work with POCO entities, queries return instances of proxy class which inherits entity types. Having some proxy instances allow us to use lazy loading. When we create an entity in order to attach it to the context, we can do a new on our entity...

French ALT .NET Demo

Last week, I spoke at an EF session for the french ALT .NET community. During its course, I made a WCF demo with EF POCO and a sort of LINQ provider in the client part . This provider is very simplistic (made in less than 15 minutes), isn't thread...

How to use LINQ extension methods on non generic IEnumerable?

LINQ extension methods are great but... it's not so cool when we use non generic collections as it is often the case with Sharepoint or TFS APIs. Likely, we have two LINQ extension methods Cast and OfType which allow us to transform our non generic...
Posted by Matthieu MEZIL | 4 comment(s)
Filed under: , ,

Code factorization with delegate

I want to write an extension method Sum on IEnumerable<int> and an extension method Sum on IEnumerable<decimal>. public static int Sum( this IEnumerable < int > source) { int value = 0; foreach ( int item in source) value += item; return...
Posted by Matthieu MEZIL | with no comments
Filed under: ,

EDM Designer

I didn’t blog for a (too) long time which is strange for me. I received some emails asking if I was ok and I found in this a similitude between Scott Guthrie and myself . Lol So what did I do during my nights this last month? No I don’t sleep...

C# compiler and implicit keyword: can be better

Imagine the following code: class A { public static implicit operator B ( A a) { return new B (a); } } class B { public B( A a) { } } This code compile without error and it's normal. Now imagine the following one: class A { public static implicit...
Posted by Matthieu MEZIL | with no comments
Filed under: , ,

C#4: dynamic keyword

With C#4, there is a new keyword: dynamic. This keywork allow you to use an object without defining its type and to “try” to call any method. This allows you for example to call a javascript method, to do interop COM and of course to use dynamic...
Posted by Matthieu MEZIL | 4 comment(s)
Filed under: ,

Bug with IQueryable and yield syntax: System.BadImageFormatException "An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)"

I find a bug if you mix IQueryable and yield syntax. After Diego has changed a little bit my sample to reproduce it, this is the code he sent to the C# team: class Program { static void Main( string [] args) { try { GetCategoryProductsUsingQueryable(...

Summer Geek Quizz

Mitsu makes again his geek quizz in French which is some quizz on C# 3.0 and LINQ. And I will do the same. For my first quizz, the idea is to write a method which has an IEnumerable<IEnumerable<T>> parameter and which returns all the distinct...
Posted by Matthieu MEZIL | 2 comment(s)
Filed under: , ,

With SP1, VS 2008 manage anonymous types with C# Debugger

Sreekar Choudhary wrote a post about a new (VS 2008 SP1) C# debugging management. We can now use an anonymous type to do a cast or instanciate anonymous types in the C# debugger .
Posted by Matthieu MEZIL | with no comments
Filed under: ,

Reflector IL to C# Bug

I was watching Entity Framework code when I found this code: switch ( this .<>1__state) { case 3 : case 4 : break ; default : return ; try { } finally { this . d__0.<>m__Finally6();" href="http://www.aisto.com/roeder/dotnet/Default...
Posted by Matthieu MEZIL | with no comments
Filed under: , , , ,

Entity Cloner

I do an EntityCloner which can Clone an entity single or all the graph from one entity. To clone an entity, I use reflection but the problem of Reflection is it’s far. The way to Clone a product is always the same. So I generate a Delegate on the fly...

What do you think about private and protected?

I think it should be a great thing to have two notions: class private and instance private (and the same for protected). In my mind, in a lot of case, I shouldn’t be able to do this: class C1 { private int _test = 0; public int Test( C1 c1) { return c1...
Posted by Matthieu MEZIL | with no comments
Filed under: , , ,