linq

What is the scariest LINQ function you've seen?

While working on a personal project I wanted a simple service to extract items out of Outlook and host in WCF in a "RESTful" design. In the process I came up with this rather beastly class. What other scary linq code have people have seen? public IQueryable<_AppointmentItem> GetAppointments(DateTime date) { var dayFlag = (OlDaysOf...

Iterate through a ControlCollection from a CreateUserWizardStep

Hello, I am attempting to iterate through a ControlCollection in the CreatedUser event of my CreateUserWizardStep. I have a ContentTemplate that contains a table full of checkboxes that I am using to gather a user's availability during the week. For the sake of brevity I will paste my code on pastebin. Here is a link to the .aspx page....

Using LINQ how do you filter a list of strings for values that match the pattern "q1, q2" etc.?

Hi, This should be a simple one but I'm looking for the best answer with at least some regard for performance as well as elegance. I have a list of strings and some of the values are of the form q1, q2, q3 etc. I'd like to select these. What would be the best method of doing this? ...

Selecting an entity doesn't subselect associated entities

I'm learning ASP.NET MVC (and MVC in general) and all the help online I find only demonstrates using a single table, not relations between multiple tables. I'm running a query that I expect should also return associated entities, but it's not and can't figure out what I'm missing. I appreciate your help! I have the following data: Ti...

Mapping a database value to a TimeSpan using dbml

I need to store a time offset in a database column (for example, 12:25 AM, just the time, no date). I would like to use the nice data visual modeling capabilities in Visual Studio 2008 to generate dbml and the code to go with it. The database is Sql Server 2005. Since a TimeSpan is essentially an Int64 (aka long) containing the number ...

LINQ to objects changing the display column

Hi, hope some can help - my webservice returns an object with certain fields i use ling to object to filer the display an dthen bind the annonymous type to the grid. is there a away to do a similar select as to change the display of the grid column? for example Dim wsr As wsTest.Service = New wsTest.Service Dim objs(...

Linq to SQL - how to dynamically filter by columns not in select

The Problem Using Link to SQL I would like to filter by columns that I do not want returned in the select statement. This works fine as long as the query is built all at once. In situations where I try and build the where clause dynamically, I get a compile time error because the column is not included in the select. Example WORKS...

Linq to SQL - Don't fetch a particular column

Is there a way to not fetch a specific column using linqtosql without having to use an anonymous type and specify each returned filed individually? We use SQLMetal to generate the dbml file which contains all the types into which to put the queried data results. However, when select columns are included in the linq query, the results g...

Is there a LINQPad equivalent to a DataContext class?

I've just begun using LINQPad and so far I like it but most tutorials I have come across for LINQ TO SQL make use of a DataContext class which is generated by Visual Studio for persisting updates etc. I am also fairly new to LINQ TO SQL so my question is what is the equivalent of the following in LINQPad (if there is one)... MyDbDataCon...

table alias in linq edmx

I am trying to replicate something that would be simple with a stored procedure. I have a set of tables like so: acem__main acem__child beta__main beta_child xyz__main xyz__child In my edmx, I have the acem_main and acem_child linked via a primary/secondary key. However depending on who logs in I would like to utilise the data of eith...

C# using LINQ to remove objects within a List<T>

I have LINQ query such as: var authors = from x in authorsList where x.firstname == "Bob" select x; Given that authorsList is of type List, how can I delete any Author that appears within 'var authors' from authorsList? Note: This is a simplified example for the purposes of the question. ...

Get list of titles from xml files...

Hello, I am trying to get titles of xml files from a folder call "bugs". My code: public virtual List<IBug> FillBugs() { string folder = xmlStorageLocation + "bugs" + Path.DirectorySeparatorChar; List<IBug> bugs = new List<IBug>(); foreach (string file in Directory.GetFiles(folder, "*.xml", SearchOpti...

Is there an easy way to append lambdas and reuse the lambda name in order to create my Linq where condition?

I have a user control which takes a Func which it then gives to the Linq "Where" extension method of a IQueryable. The idea is that from the calling code, I can pass in the desired search function. I'd like to build this search function dynamically as such: Func<Order, bool> func == a => true; if (txtName.Text.Length > 0) { //add it...

LINQ to SQL - Tracking New / Dirty Objects

Is there a way to determine if a LINQ object has not yet been inserted in the database (new) or has been changed since the last update (dirty)? I plan on binding my UI to LINQ objects (using WPF) and need it to behave differently depending whether or not the object is already in the database. MyDataContext context = new MyDataContext()...

how to make an array size cap

I have two string arrays string[] input; //user input could be any size string[] output; //a copy of user input but, should not be larger than 50 if input length <= 50, then output is an exact copy of input. if input array length > 50 then it will copy only 50 elements from input It must have the first and last element from input an...

How to check for nulls in a deep lambda expression?

How can I check for nulls in a deep lamda expression? Say for example I have a class structure that was nested several layers deep, and I wanted to execute the following lambda: x => x.Two.Three.Four.Foo I want it to return null if Two, Three, or Four were null, rather than throwing a System.NullReferenceException. public class Test...

Linq dynamic select casting issue

I want to run a query to get a string array of distinct "logName" items for a logType. The following works great: Dim stringArray() As String = (From item In dc.Vw_Logs Where item.LogType = [Passed in logType] Select item.LogName Distinct).ToArray() However, this only works when a specific LogType is set. I would like the ...

Nested Linq Queries

What is valid Linq Statement for from a in Active_SLA where a.APP_ID == (from f in FORM_PAGES where f.PAGE_ADDRESS == @Address select f.APP_ID) && a.PERSON_ID == (from p in PERSON_DEVICES where p.DEVICE_NUMBER == @number select p.PERSON_ID) select a.PRIORITY ...

What design pattern should I use to create an easy binding map between a query and textboxes for Linq search screens?

Over and over, I find myself developing WinForm business application screens that have a bunch of text boxes for search criteria, then a search button. These are mapped into an expression using Linq, then passed onto my Linq2Sql layer. I'd like to create an easy way to "bind" these textboxes to the underlying query using different opti...

DbLinq Problems (Keyword New or MemberInit throws exception)

I'm migrating a huge web application from SQL Server to MySql. The application uses Linq so i'm using DBLinq. Currently most things are working properly except for that on a few pages i get a strange error. It all started with this: Property 'Int32 ForumID' is not defined for type 'DbLinq.Data.Linq.Table`1[CPost]' I've obviously got ...