linq

RegEx for LINQ like syntax

I have a string in the format: MyList.Where(abc).GroupBy(def).Sum(ghi) The Where & GroupBy parts are optional as is the argument to the function, so. ThisList.Count is also valid. I'm trying to find a RegEx string that will match this and return the values: The List name (e.g. MyList), the where condition (e.g. abc), the GroupBy a...

How can I get all objects with a timestamp greater than X from an EF repo?

I have a timestamp (rowversion) column (called t_stamp) in my tables. I use EF4 as my ORM. I see that the timestamp fields become byte[] properties on my objects. I want to use LINQ something like this: byte[] last = 0x00782342 from o in _db.Objects where o.t_stamp > last select o But that doesn't work because I can't use > on a byt...

How parse a string as linq exprssion ?

I've this linq to devforce expression : (from r in mgr.testTables select r).OrderBy(r => r.id); I want to specify sorting column name as a string, I need something like this : string orderBy = "r => r.id"; (from r in mgr.testTables select r).OrderBy( orderBy ); is there any way to parse a string as linq expression ? ...

LINQ - How can I give a child object in a select statement a reference to its parent?

I'm trying to do something like this: List<FundEntity> entities = this.tFunds .Select(f => new FundEntity() { ID = f.fundID, Name = f.name, CapitalCalls = f.tCapitalCalls .Select(cc => new CapitalCall() { ID = cc.capitalCallID, ...

How can I optimise this LINQ query to only execute a single SQL command?

I am using Linq-To-Sql to populate my business layer. Here is a snippet of a query I am working on: fund.FundEntities = fundGroup.tFunds .Select(fe => { var fundEntity = new FundEntity() { BankAccount = null, CloseDate = fe.closeDate ?? new DateTime(), Commitment = fe.commitmen...

Interesting libraries based on LINQ

Every man and his dog seems to be adding an implementation of LINQ to something. http://linqtotwitter.codeplex.com/ http://blogs.msdn.com/b/aconrad/archive/2007/12/10/linq-to-rest.aspx http://linqtowikipedia.codeplex.com/ http://www.codeproject.com/KB/linq/LINQtoCSV.aspx http://mhinze.com/linq-to-nhibernate-in-10-minutes/ it's even b...

Linq or ADO or ?

Building an application with a database that has the ability to get big not HUGE but definate big tables with a million records +. I just saw somewhere that LINQ isn't good for Big Datbases. Front end will be in Silverlight and I was really looking forward to using its Skip and Take functionality for the Asynchronous calls to speed u...

Can you compile a LINQ to Entities query that is composed with if statements?

I have a fairly complex LINQ to Entities query I'd like to try compiling because it's a bit slower than I'd like. I build it in a series of steps though. Here's a simple example: public static List<Employee> GetEmployees(EntityContext ctx, bool showTerminated) { var q = ctx.Employees; if(showTerminated==false) { q ...

Does calling Select() or GroupBy() in Linq to entities trigger querying the database?

I have a hard time telling what operations in linq cause a SQL command to be issued to the database. I know calling ToList() or iterating w/ foreach will cause the query to run but do Select and GroupBy cause the code to execute on the database? ...

How To Use LINQ To Find Matching Data Against A List Of Strings

Hello, I have a specialized string dictionary of (string, string) (_RulesAndTheirDescriptions) that contains the name (key) and description (value) of methods in a given class. I currently do the following query to search for a match on the key or value and then bind that to a grid. Works great! Dim Results = From v In _RulesAndThe...

Linq - SingleOrDefault and NerdDinner

Hi I'm getting into LinqToSql and using the NerdDinner tutorial. I'm trying to understand the syntax and would like to write out in more verbose fashion what is happening in the first line, which works. Question: How can I write the first query something like the commented out code (which doesn't work). public Dinner GetDinner(int...

How do I subgroup a group in linq?

I'm trying to subgroup a group using linq. This is proving to be more difficult than I thought. So far I took a quick and dirty approach but it's not as efficient as I would like. Can these two linq statements be simplified into one?: var basketBalls = from Ball ball in Balls where ball.IsBasketBall()) ...

How do you specify a database column that contains a space in a linq statement

I thought this would have been quite common but can't find anything on this. I'm trying to query columns that have spaces immbedded within them. For the life of me I don't see a way of selecting them when I'm trying to assign them to an alias when creating an anonymous type result. Here's the code, but not sure how to go from here: D...

Custom Inclusive TakeWhile(), is there a better way?

I've written a custom LINQ extension method that extends the TakeWhile() method to be inclusive, rather than exclusive when the predicate is false. public static IEnumerable<T> TakeWhile<T>(this IEnumerable<T> source, Func<T, bool> predicate, bool inclusive) { source.ThrowIfNull("source"); predica...

LINQ to SQL context.SubmitChanges - How to get error details?

Hi! I'm working on an application where a lot of data is inserted into an SQL database at once. I use LINQ to SQL, and have something like this as my insert operation: foreach (var obj in objects) { context.InsertOnSubmit(obj); } context.SubmitChanges(); Here's the problem: If I get an exception (for instance, DuplicateKeyException),...

How to generate SQL COUNT(*) OVER (PARTITION BY {ColumnName}) in LINQ-to-SQL?

Is it possible to generate the following SQL query by using LINQ-to-SQL query expression or method chains which is defer-executable? Data Structure Select Distinct ClassRoomTitle, Count(*) Over(Partition By ClassRoomNo) As [No Sessions Per Room], TeacherName, Count(*) Over(Partiti...

Syntax error when performing OrderBy<T> on an IEnumerable List

The error message I receive is: At least one object must implement IComparable The code causing this is below: private static IEnumerable<Result> setOrderBy(IEnumerable<Result> value, string order) { if (order.Equals("ASC")) { //value = value.OrderBy(c => c, new SearchService.ResultComparer<Attribute>()); value...

Hierarchical layering in Linq

If I have a set of employee data similar to: var users = new[] { new {SupervisorId = "CEO", UserId = "CEO", UserName = "Joe"}, new {SupervisorId = "CEO", UserId = "CIO", UserName = "Mary"}, new {SupervisorId = "CIO", UserId = "XDIR", UserName = "Ed"}, new {SupervisorId = "...

GroupBy in lamda expressions

from x in myCollection group x by x.Id into y select new { Id = y.Key, Quantity = y.Sum(x => x.Quantity) }; How would you write the above as a lambda expression? I'm stuck on the group into part. ...

LINQ Query Returns List of Lists

I have a query: from m in dc.ReportingMonths where m.Month.Value == month select (from k in m.KPI_Actives where k.DateActive.Year == year select (from r in dc.ReportingViews where r.KPIID == k.KPIID select r) ); Obviously, because it is nested LINQ queries - each returning an IQueryable I get a s...