linq

LINQ to SQL Join

I'm new to LINQ so apologies if this is a simple answer. I'm trying to do a SQL join and have the following code based on examples I've seen on SO and elsewhere: var query = from e in db.Events join ec in db.EventCategories on e.ID equals ec.EventID join c in db.Categories on ec.CategoryCode equals c.CategoryCode join ep in ...

Public Active directory for testing.

I need to write some .NET code for listing user and groups. I am planing to use LINQ. I do not have access to the Active directory for testing. I do not have a server and can not set up my own Active directory. Are there any public Active directory that I could use for testing. The code is only reading data from the Active directory and ...

Where Clause and sending 2 unmatched params to a custom Method

Ok, I'm trying to get this working. This is my first time using LINQ. So far it's ok except a little snag that I've been trying to figure out. Scenario: I have 2 generic lists I'm sending to a method. That method has this in it below to give me back a list of only those objects (union) where a certain ID is found in both. The lis...

Entity Framework: is there a complete list of supported IQueryable extension methods?

I'm looking for this list for Entity Framework. Ideally, I'd like to have a list of other supported methods (or members - e.g. constructors), e.g. for DateTime type. ...

Referencing object's identity before submitting changes in LINQ

Hi, is there a way of knowing ID of identity column of record inserted via InsertOnSubmit beforehand, e.g. before calling datasource's SubmitChanges? Imagine I'm populating some kind of hierarchy in the database, but I wouldn't want to submit changes on each recursive call of each child node (e.g. if I had Directories table and Files ta...

LINQ to SQL: is there a complete list of supported IQueryable extension methods?

I'm looking for such list for LINQ to SQL. Ideally, I'd like to have a list of other supported methods (or members - e.g. constructors), e.g. for DateTime type. ...

How to write sum calculation based on ria service?

When using ria service for SL app, I can issue following async call to get a group of entity list. LoadOperation<Person> ch = this.AMSContext.Load(this.AMSContext.GetPersonQuery().Where(a => a.PersonID == this.performer.PersonID)); But I want to get some calculation, for example, sum(Commission), sum(Salary), the result is not entity...

Corner case in using lambdas expression in base constructor

In the Framework we are building we need the following pattern: public class BaseRenderer { Func<string> renderer; public BaseRenderer(Func<string> renderer) { this.renderer = renderer; } public string Render() { return renderer(); } } public class NameRenderer : BaseRenderer { public st...

Linq to XML: How do you determine if something of type "var" is null or empty?

So, I've got a small chunk of stabby, pointy xml that looks like this: <Groups UseGroup='True'> <Group>1264,182,1979</Group> </Groups> And I've got a small chunk of linq that gets the value from that looks like this: var group = from a in xml.Descendants("Groups") select a.Element("Group").Value; It's all fine and dandy...

C# Linq Inner Join

I want to select the persons only who are having pets. when I execute the query var query = from p in people join pts in pets on p equals pts.Owner into grp select new {grp=grp,PersonName=p.FirstName}; Person does not have pet also get se...

Load result of Linq-to-DataSet query with join into datatable

I have a linq to dataset query that joins two tables and extracts the desired parameters from each. I need to get them into a DataTable to bind to a DataGridView. The example I found for doing this on MSDN is a trivial example taking a single value from a single table, but when I tried to change my query to follow it I was unable to do...

Linq to entities casting error

I am getting this error and I have collection of anonymous Datarows and each item contains two datarows. How to cast this? Unable to cast object of type 'WhereSelectEnumerableIterator`2[VB$AnonymousType_0`2[System.Data.DataRow,System.Data.DataRow],VB$AnonymousType_0`2[System.Data.DataRow,System.Data.DataRow]]' to type 'System.Data.Enume...

Why does my LINQ to SQL query fail the first time ("Row Not Found or Changed") and succeed the second time?

I'm using LINQ to SQL in ASP.NET MVC. I wrote some new code to update Orders in our system, and as far as I can tell it's exactly like a hundred other similar pieces of code I've written (grab the object, update some fields, submit changes). This time though, when I try to run the update, I get a "Row not found or changed" LINQ excepti...

Return value of stored procedure is correct but column values are all NULL

I'm working with the C# membership provider and transferring it to LINQ along the way. I'm having trouble pulling the results from a stored procedure in MS SQL. The procedure does some work to set variables and then selects the variables before setting the return value of 0. When I run this in MS SQL to test it works fine. When I run i...

How to tell Linq which Database Version to use

i am using sql server 2005 and I think Linq generating queries for a different database version. I got the query string that linq was producing and pasted the linq directly in SQL Server Management studio and it failed with many errors. But the query works well if Linq is used. Any ideas what could be going on. If linq needs to know what...

Binary Operator Equal is not defined... troubles comparing MemberExpressions in a generic repository

I have a generic SelectAllByKey method in my repository: public IList<E> SelectAllByKey(string columnName, string key) { KeyProperty = columnName; Expression rightExpr = null; rightExpr = Expression.Constant(key); // First we define the parameter that we are going to use the clause. var ...

C# - Checking Index values of two sets

From two sets var set1 =new int[] { 1, 2, 3 }; var set2 =new int[] { 100, 200, 300 }; How to check index value of elements in set1 and set 2 ? if index value of elements of set1 equals to index value of elements of set2 then i want that pair like {1,100} ,{2,200},{3,300}. Some incomplete code var pairs=from n1 in set1 ...

LINQ puts unwanted trailing spaces on strings

Hi I have a very annoying problem with LINQ and MS SQL Server. Im currently making some software in WPF C# and use LINQ to generate classes from the data in the database. However, when i update a nvarchar or varchar field in the DB from my program, LINQ adds trailing spaces to the string! I have a field in a table defined like this: ...

String.StartsWith not working with tilde ("~") characters LINQ to SQL?

For some reason, my call to IEnumerable.Where() using String.StartsWith() appears to be giving different results depending on whether it's being used in LINQ-to-SQL or standard LINQ (-to-objects). If I add in a call to ToList() on what's otherwise the same call, I get different results back: var withToList = MyDataContext.MyEntities.ToL...

Linq : select value in a datatable column

Hi, How do you use LINQ (C#) to select the value in a particular column for a particular row in a datatable. The equivalent SQL would be: select NAME from TABLE where ID = 0 Thanks in advance. ...