LINQ with SQLite (linqtosql)
I’ve recently discovered DBLinq, which supports SQLite among other DB:
I’ve recently discovered DBLinq, which supports SQLite among other DB:
That’s the GroupBy operator. Are you using LINQ to Objects? Here’s an example: using System; using System.Collections.Generic; using System.Linq; public class Test { static void Main() { var users = new[] { new { User=”Bob”, Hobby=”Football” }, new { User=”Bob”, Hobby=”Golf” }, new { User=”Bob”, Hobby=”Tennis” }, new { User=”Sue”, Hobby=”Sleeping” }, new { User=”Sue”, … Read more
One option (for LINQ to Objects) would be to create your own LINQ operator: // I don’t like this name 🙁 public static IEnumerable<TResult> SelectWithPrevious<TSource, TResult> (this IEnumerable<TSource> source, Func<TSource, TSource, TResult> projection) { using (var iterator = source.GetEnumerator()) { if (!iterator.MoveNext()) { yield break; } TSource previous = iterator.Current; while (iterator.MoveNext()) { yield return … Read more
Well, the easiest way would be to do it at the client side rather than the database side, and use the overload of Select which provides an index as well: public List<ScoreWithRank> GetHighScoresWithRank(string gameId, int count) { Guid guid = new Guid(gameId); using (PPGEntities entities = new PPGEntities()) { var query = from s in … Read more
Why not discard the data context and simply replace it with a new instance?
The problem with your code is that PowerShell cannot decide to which specific delegate type the ScriptBlock instance ({ … }) should be cast. So it isn’t able to choose a type-concrete delegate instantiation for the generic 2nd parameter of the Where method. And it also does’t have syntax to specify a generic parameter explicitly. … Read more
You can make your own extension calculating it public static class Extensions { public static double StdDev(this IEnumerable<double> values) { double ret = 0; int count = values.Count(); if (count > 1) { //Compute the Average double avg = values.Average(); //Perform the Sum of (value-avg)^2 double sum = values.Sum(d => (d – avg) * (d … Read more
You just need to name the anonymous property the same on both sides on new { t1.ProjectID, SecondProperty = true } equals new { t2.ProjectID, SecondProperty = t2.Completed } into j1 Based on the comments of @svick, here is another implementation that might make more sense: from t1 in Projects from t2 in Tasks.Where(x => … Read more
IEnumerable<T> represents a forward-only cursor of T. .NET 3.5 added extension methods that included the LINQ standard query operators like Where and First, with any operators that require predicates or anonymous functions taking Func<T>. IQueryable<T> implements the same LINQ standard query operators, but accepts Expression<Func<T>> for predicates and anonymous functions. Expression<T> is a compiled expression … Read more
LINQ to entities: Video walkthroughs Channel 9 video Entity framework FAQ Entity framework performance I’ve got a lot more I tagged on Delicious.com.