linq

LINQ - joining multiple lists

I've looked at the 101 Linq Samples here but I can't see anything like this in that list. If I'm just not seeing a relevant example there, please link to it. If I have these 3 classes: class Student { int id; string name } class Course { int id, string name } class Enrolment { int studentId; int courseId; } How would I use LINQ to g...

Performance Difference between LINQ and Stored Procedures

Related LINQ-to-SQL vs stored procedures? I have heard a lot of talk back and forth about the advantages of stored procedures being pre compiled. But what are the actual performance difference between LINQ and Stored procedures on Selects, Inserts, Updates, Deletes? Has anyone run any tests at all to see if there is any major diffe...

How do I search the collection of a collection in my LINQ Where clause?

I've got the following ADO.NET Entity Framework Entity Data Model: I want to find all the Policyholders with both a Service of a given Id and also a Keyword of a given Status. This LINQ Does Not Work: Dim ServicesId As Integer = ... Dim KeywordStatus As Integer = ... Dim FoundPolicyholders = From p As Policyholder In db.Policyholde...

How to Get XML Node from XDOcument

Hi, How to Get an XML Element from XDocument using LINQ ? Suppose I have an XDocument Named XMLDoc which is shown below: <Contacts> <Node> <ID>123</ID> <Name>ABC</Name> </Node> <Node> <ID>124</ID> <Name>DEF</Name> </Node> </Contacts> XElement Contacts = from xml2...

LINQ to SQL Insert Sequential GUID

I have a database that is part of a Merge Replication scheme that has a GUID as it's PK. Specifically the Data Type is uniqueidentifier, Default Value (newsequentialid()), RowGUID is set to Yes. When I do a InsertOnSubmit(CaseNote) I thought I would be able to leave CaseNoteID alone and the database would input the next Sequential GUI...

How do I combine the keys and values of a Dictionary into one List using LINQ?

I have a dictionary, where the key is a string and the value is a list of strings that correspond to that key. I would like to display all of the keys in the dictionary, with the values associated with that key tabbed in underneath that key. Something like this: Key 1 Value 1 Value 2 Value 3 Key 2 Value 1 Value 2 I...

LINQ-to-SQL and Extension method in subQuery

My extension method is: public static IEnumerable<T> FilterCultureSubQuery<T>(this Table<T> t) where T : class { return t; } I tried to use it in this query var test = from p in t.Products select new { Allo = p, Allo2 = (from pl in t.ProductLocales.FilterCultu...

Linq To SQL and Having

I am fairly new to Linq To SQL but trying to run what should be a fairly simple SQL query and can't figure out how to make it play nice in LINQ. SELECT Users.Id, Users.Id AS Expr1, Users.FirstName, Users.LastName, User_x_Territory.UserID FROM Users LEFT OUTER JOIN User_x_Territory ON User_x_Territory.UserID = U...

Has someone recent and trusted news about Linq to XSD?

or is there a project with the same goals? maybe with IQueryable provider ready to use.. am I asking too much? ...

Help with Tricky Linq Group by for time ranges

I have a class that represents a shift that employee's can work: public class Shift { public int Id { get; set;} public DateTime Start {get;set;} public DateTime End { get; set;} public DayOfWeek Day { get; set;} } And say I have a list of these shifts for a single employee: List<Shift> myShifts; I know I can get group the shifts ...

Filtering necesary data with Linq

Have been playing around with linq but there is one thing I cant seem to make it do.. here is the situation.. lets say you have.. public class Job { public DateTime? CreatedDate { get; set; } } public class Company { public string Name { get; set; } public List<Job> Contract { get; set; } } Now what I want to do is popula...

How do I order a Group result, in Linq?

Hi folks, I have the following linq query, which works fine. I'm not sure how i order the group'd result. from a in Audits join u in Users on a.UserId equals u.UserId group a by a.UserId into g select new { UserId = g.Key, Score = g.Sum(x => x.Score) } the results are currently ordered by UserId ascending. I'm after Score descending. ...

Too many outer joins in LINQtoSQL generated SQL

Hi, I have a question about a SQL statement generated by a LINQ2SQL query. I have two database tables (VisibleForDepartmentId is a foreign key): AssignableObject Department ---------------------- ------------ AssignableObjectId ┌────> DepartmentId AssignableObjectType │ VisibleForDepartmentId ───┘ ...

Load DataTable Using Linq - Convert C# to VB.Net

I found the following example on http://www.erictobia.com/2009/02/21/LoadADataTableWithLINQ.aspx Unfortunately, I need it in VB and it's using some constructs that neither I nor the automated code converters reciognize. Anyone out there know how this should be written in VB.Net? (the problem spot is the "select new {...") PeopleData...

LINQ - grouping and aggregation

If I have these 3 classes: class Student { int id; string name; } class Course { int id; string name; } class Enrolment { int studentId; int courseId; DateTime enrolmentDate; } Then using this: IEnumerable<Course> FindCoursesForStudent(Student student) { return from enrolment in Enrolments where enrolment.studentId ==...

Linq Select Compound From

Hi, I'm experimenting with linq compount selects. I find the following query not to return any element: Dim q = From s In d.GetChildRows("DossierSinistri") _ From i In s.GetChildRows("DossierIncarichi") _ Select s while the following does: Dim q = From s In d.GetChildRow...

suggest me a .net architecture to implement

Hello Experts, I am about to start a new project for the catering institute where following list of modules needs to be covered. TELEPHONIC INQUIRY PROCEDURE: where user will fill up online form and will be saved in db. Follow up module will be associated with it to manage follow up and after he paid the fees for prospects, his exam ...

LINQ Conditional Group

Is it possible to write a LINQ statement with a conditional group clause? Here is basically what I'm trying to do: bool someFlag = false; var result = from t in tableName group t by new { (someFlag ? 0 : t.FieldA), t.FieldB } into g select g; So basically if someFlag is set to true, I want to group only by FieldB, but if it's ...

ContextSwitchDeadLock SQLCE LINQ query

Have anyone got an exception like this "ContextSwitchDeadLock" RANDOMLY in your program executions? I have a query linq against an SQL CE source, a very simple one From Entry in DataContext.Resources Select Entry Where Entry.Key = Key -Key is of type String. After I queried, whenever I try to iterate the results, the program gets st...

lambda expression to verify list is correctly ordered

I want to write a lambda expression to verify that a list is ordered correctly. I have a List where a person has a Name property eg: IList<Person> people = new List<Person>(); people.Add(new Person(){ Name = "Alan"}); people.Add(new Person(){ Name = "Bob"}); people.Add(new Person(){ Name = "Chris"}); I'm trying to test that the list i...