Getting VS 2008 & mysql to play nicely!

I love linq!

But getting mysql to place nicely isn’t so straight forward.   To get mysql running on .net 3.5 or 4.0 I had to do the following:

1.  Install the mysql .net connector
2.  Add the MySQL Data Provider line in the DbProviderFactories to your machine.config file:

<system.data>
    <DbProviderFactories>
        <add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.1.0.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"/>
    </DbProviderFactories>
</system.data>

(see here for more information)

3.  Restart Visual Studio
4.  Add your models and go nuts!

This Stack Overflow question helped

Good luck!

Linq – Multiple Group By

This has been bugging me for a LONG time!

I’ve finally found an example of how to group by multiple values using LINQ:
IList doc_infos = new List();

doc_infos.Add(new doc_info { region = "UK", price = 100, currency = "US" });
doc_infos.Add(new doc_info { region = "US", price = 100, currency = "US" });

var docs = doc_infos.GroupBy(x => new { x.price, x.currency })
.Select(group => new { d = group.Key, Count = group.Count() });

For more examples, have a look here.

Linq – not in

I’m doing some work with LINQ and outer joins.

I found a few links, but it wasn’t what I was looking for.

I then thought I’d try a different direction and found this!

NorthwindDataContext dc = new NorthwindDataContext();
dc.Log = Console.Out;
var query =
from c in dc.Customers
where !(from o in dc.Orders
select o.CustomerID)
.Contains(c.CustomerID)
select c;
foreach (var c in query) Console.WriteLine( c );

This is exactly what I was after! I thought I’d share the love and post a comment – but what? I have to register to post comments???

I would be a little more understanding if Marco Russo’s site used some generic, open authentication system. But he didn’t.

(If you want to know how easy it is to implement Twitter, Facebook, OpenID or other identification methods, IT Conversations recently did a podcast on how they overcame this problem.)

Rock on!