linq

the point of the Field extension method

What is the point of the Field extension method on DataRow (for untyped DataTables)? Here is a comparison of using Field or not using it. with Field: myRow.Field<Guid>("myColName") without Field: (Guid)myRow["myColName"] I don't see any compelling improvement. ...

Database problem moving from VS Development Server to IIS7

I have a project I am trying to move to run on IIS7 instead of the Visual Studio Development Server. Everything works on VS Development Server but when moving to IIS7 its seems to not be able to read anything from the database, but doesn't give a database error, instead it gives a NullReferenceException on the information I'm trying to ...

Wildcard search for LINQ

Hi there, I would like to know if it is possible to do a wildcard search using LINQ. I see LINQ has Contains, StartsWith, EndsWith, etc. What if I want something like %Test if%it work%, how do I do it? Regards ...

How can I set the value of a column for every row in a table using LINQ?

Lets say I have a File table with the column, "File_ID". How can I write a quick LINQ query/statement to set every "File_ID" in the File table to "1"? I'm using LINQPad in Statement mode, but that doesn't matter really. ...

How can I query this hierarchical data using LINQ?

I have 3 kinds of objects: Agency, BusinessUnit and Client (each with their own respective table) In terms of hierarchy, Agencies own BusinessUnits, and BusinessUnits own Clients. I have 3 C# POCO Objects to represent them (I usually select new {} into them, rather than use the LINQ generated classes): public class Agency { public...

Is there an implementation of IQueryable over DbDataReader?

I have a lot of existing code which uses raw ADO.NET (DbConnection, DbDataReader, etc). I would like to transition to using LINQ to SQL for new code, but for now put both the existing and new code behind a unified set of Repository classes. One issue I have is this: I would like the Repository classes to expose result sets as IQueryab...

Does Linq has "Difference" ?

I have a sql statement that uses Difference => http://msdn.microsoft.com/en-us/library/ms188753.aspx I do this in a stored proc but i want to change to LINQ. Is there an equal to Difference in LINQ? Ex: WHERE (DIFFERENCE(C.LastName, ''' + @name + ''') >= 4 Thanks. ...

What does it mean to filter a collection 'vertically' and 'horizontally'?

In the Essential C# 3.0 book, there is a part where it says: "Projection using the select() method is very powerful. We already saw how to filter a collection vertically (reducing the number of items in the collection) using the Where() standard query operator. Now, via the Select() standard query operator, we can also ...

How can I make DataTable enumerable ?

I cannot use AsEnumerable() on DataTable, I'm using C# 3 but I'm just targeting 2.0 framework (LINQ capability is courtesy of LINQBridge). Is there any way I can make DataTable enumerable without using Select() ? bool isExisting = (bdsAttachments.DataSource as DataTable).Select().Any(xxx => (string)dr["filename"] == filename); [EDIT]...

How to select values within a provided index range from a List using LINQ

I am a LINQ newbie trying to use it to acheive the following: I have a list of ints:- List intList = new List(new int[]{1,2,3,3,2,1}); Now, I want to compare the sum of the first three elements [index range 0-2] with the last three [index range 3-5] using LINQ. I tried the LINQ Select and Take extension methods as well as the SelectMa...

How can i convert IQueryable<string> to a string array?

Hi, if I do this... rowNames = _myDB.RowSet.Where(r => (r.RowId >= minId) && (r.RowId <= maxId)) .Select(r => r.RowName); it returns an IQueryable, how can I put this into: string[] myStringArray? ...

Usage Of Lambda Expression in Practical Programming

I am an experienced developer in C# and working on LOB application from last 7 Years, I have some issues in understanding the usage of Lambda expression in programming. As far as I understand, it is useful in case of Working with LINQ (Grouping, Select,Where etc..) We can pass Lambda expression to any function as argument, so it can ...

Query Db from within a Linq Query - C#

I perform a query on my XML file with Linq and when I parse and obtain data from the XML document, I need to go against a DB to populate 2 properties of my object. I can perform 2 calls as my snipet shows, but I would like to make just one call and obtain the result to populate the 2 properties XDocument recentOrdersXDoc = GetResults(...

Subsonic 3 Union Possible?

I have a schema like so. Menu->Pages->PageRoles->ASPNetRoles Menu has a CategoryID. I want to return all Menu items with a CategoryID of 6. Some Menu items have a foreigh key of PageID. Pages can have 1 or more roles against them. I can check the currently logged in users roles and make sure that they are in the results by joining the...

Linq to sql truncating string returned by Stored Procedure

I have asked this question before. but i was not able to get any answer. may be i wasnt very clear. let me give some more details. I have a SP which returns a long string. here is dbml file code [Function(Name="dbo.spX")] public ISingleResult<spXResult> spX([Parameter(DbType="VarChar(8000)")] string str) { IExecuteResult result = t...

Explain in small words why IQueryable<T> is needed

There's this. Can you do a better job explaining (in small words so I understand :)) why we need a marker interface which doesn't add any methods over IEnumerable? ...

Is LINQ to Everything a good abstraction?

There is a proliferation of new LINQ providers. It is really quite astonishing and an elegant combination of lambda expressions, anonymous types and generics with some syntax sugar on top to make it easy reading. Everything is LINQed now from SQL to web services like Amazon to streaming sensor data to parallel processing. It seems like s...

Dynamic Linq To Sql With ComboBox and Column.Contains

I have a text box, combo box, button and DataGridView on a form that is used to search and return customer information from a MSSQL view (vCustomer). It works great, but I know my code can be more efficient. The four items in the combobox represent columns to search. Is there a simple way of converting the following to dynamic LINQ to...

Optimize Map Child Collection in Linq To SQL

When i query a collection of Persons from the database i want to select the list of positions each person has. I chose to map Linq Entities to a domain model so i have to build a custom entity for each position. When the query is executed i see in the profiler that for each person loaded an additional select of positions is executed le...

How to load an xml document from an openxml file without saving the xml file on disk?

I need to load an xml document which is stored in an openxml file.Document has to be loaded in an Xelement or Xdocument. Is that possible without saving the xml file to disk? I would prefer code in vb.net but c# is ok and using system.io.packaging ...