The count error is an interesting one.
Say I have this query:
LinqMetaData metaData = new LinqMetaData(adapter);
var count = (from o in metaData.Order
where o.EmployeeId == 2
select new
{
o.Customer
}).Distinct().Count();
The distinct should be applied to the set of customers. So the result should be 62, not 110. However the customer projection is a nested set (as you first have to fetch the orders when you can fetch the customers), which isn't possible as the count is a db aggregate so the projection is inside a query, ran inside the db.
I think I can solve this by removing an optimization with Count() (or CountRow): now it simply replaces the projection with count(). So doing:
var count = (from c in metaData.Customers select c).Count();
simply does:
SELECT COUNT(*) FROM Customers
To solve it it should do:
SELECT COUNT(*) FROM (SELECT ... FROM Customers)
So the query it aggregates on should be folded into a derived table. The distinct is then placed inside the derived table. It can be a bit clever when to do this, and when to simply replace the projection. I'll add some code for this in the next build.
To work around the two glitches, rewrite the query a bit so you don't need the nested set of customers, but fetch the customers directly and filter on order.