linq

Is LINQ the primary query method of Entity Framework?

I'm just starting with Entity Framework and there's a thing I don't understand: They say LINQ to SQL is being discontinued. But Entity Framework is being activelly developed and recently they released version 4.0. As far as I know, LINQ is the default method of expressing queries in Entity Framework. How come? What are they gonna do? Th...

LINQ enumeration list doesn't show up the error when accessed it for second time while debugging

I'm making a database call with linq and it is returning some results to me. Following is the code for the same: var resultSet = DataContext.GetList(id); foreach(var result in resultSet) { // do something here with result } After this, I try to access again same resultSet as below: foreach(var result in resultSet) { // do so...

XML LINQ Select to Object - Using TryParse

I'm using the following code to load a list of objects from XML using LINQ: List<Order> TheList = (from order in XMLResponse.Descendants("Order") select new Order { OrderDate = DateTime.Parse(order.Element("OrderDate").Value) }).ToList<Order>(); I would like to use DateTime.TryParse so that I can use DBNull va...

How to write this in LINQ

I have 3 tables in my database Group [GroupId, GroupName] GroupUser [GroupId, AuthorId] Author [AuthorId, AuthorName] Book [BookId, AuthorId, BookName] How do I grab a list of books for a particular GroupId? I have tried this LINQ statement: DataLoadOptions dlo = new DataLoadOptions(); dlo.LoadWith<GroupUser>(p => p.User); dlo.LoadW...

LINQ query to select based on property

IEnumerable<MyClass> objects = ... foreach(MyClass obj in objects) { if(obj.someProperty != null) SomeFunction(obj.someProperty); } I get the feeling I can write a smug LINQ version using a lamda but all my C# experience is 'classical' i.e more Java-like and all this Linq stuff confuses me. What would it look like, and is it wo...

How can i get NON contains data from list?

I have "Contains" method but I need a "Not Contains" method. Any suggestions? var ResultsOfMPD = (from m in engMpdMultiSelect where engMpdMultiItems.Select(o => o.ENG_MPD_MYTECHNIC_TASK_NO). Contains(m.ENG_MPD_MYTECHNIC_TASK_NO) select m); is there any method like that? var ...

convert list to dictionary using linq and not worrying about duplicates

i have a list of Person objects. i want to convert to a dictionary where the key is the first and last name (concatenated) and the value is the Person object. the issue is that i have some duplicates people so this blows up if i use this code: private Dictionary<string, Person> _people = new Dictionary<string, Person>(); _people ...

LINQ: Sorting on many columns dynamically

I have a query of IQueryable and want to apply sorting to it dynamically, sorting can be on many columns (asc or desc). I've written the following generic function: private IQueryable<T> ApplySorting<T,U>(IQueryable<T> query, Expression<Func<T, U>> predicate, SortOrder order) { if (order == SortOrder.Ascending) {...

How to compare two List<String> using LINQ in C#

The two lists are like LISTONE "ONE", "TWO", "THREE" LISTTWO "ONE", "TWO", "THREE" i need to compare the whether the items in two lists are in same order or not. Is there any way to do this in LINQ ...

OrderBy("it." + sort) -- Hard coding in LINQ to Entity framework?

Hi All I have been trying to use dynamic LINQ to Entity in my application for specifying the OrderBy attribute at runtime. However when using the code as described in the majority of documentation: var query = context.Customer.OrderBy("Name"); I received the following exception: System.Data.EntitySqlException: 'Name' could not be re...

Excel Data using LinQ Intersecting

My intersect in LINQ somehow dont seem to work. I have two excel sheets. I fetch it using LinQToExcel and (LinQToExcel does not support VisitSubQueryExpression i have to do some extra work). List<BoardSheet> sourceTest = (from t in Boards[0] where t["Board"] == boardName select new Circu...

DataGridView cell search using a LINQ query

Howdy, all! I'm still relatively new to LINQ, and have done more stumbling around than anything, but I have really liked what I have seen so far. So with that in mind, I have a VB.NET search routine, part of which is provided, below, that checks all Text cells in a DataGridView for a given string (inclusive), using a basic set of neste...

EntityReference can have no more than one related object.

I have two identical controller actions and two nearly identical views (one just has a different javscript file with it). One view works just fine, but the other gets hung up on this EF error: A relationship multiplicity constraint violation occurred: An EntityReference can have no more than one related object, but the query returned mo...

Code practice to handle empty result set in Linq to custom list

My Question is how do I handle a null set returned from a linq query if I am loading it into a custom class. example queryResults = queryResults.Select(p => new specialItems(p.ID, p.SECTION, p.PROGRAM, p.EVENT).ToList<specialItems>(); ... public class specialItems { public string Id { get; set; } public string Section { get...

Linq List<> problem

NorthwindDataContext db = new NorthwindDataContext(); List<Category> lresult = (db.Categories .Select(p => new { p.CategoryID, p.CategoryName, p.Description })).ToList(); In above query i don't want to use the var instead of var i want to use list<> but show me error .Why error occur ,How to correct this query. ...

LINQ Query Grabs Earliest Entry Per Other Value

Let's say I have a database that has a bunch of stock quotes TableQuotes 2010-07-22 09:45:00.000, "ABC", 102.23 2010-07-22 09:45:00.000, "EFG", 24.65 2010-07-22 09:45:00.000, "HIJ", 14.20 2010-07-22 10:45:00.000, "ABC", 104.25 2010-07-22 10:45:00.000, "EFG", 26.09 2010-07-22 10:45:00.000, "HIJ", 12.43 2010-07-23 09:45:00.000, "ABC", 101...

Problem updating LINQ results with anonymous type...read only?

Hello, I'm learning LINQ and have run into a problem. I created a simple query against the northwind db, and I'm shaping the fields that should be returned. The problem is After run , I can't modify any of the fields in my AspxGridView . <dxwgv:ASPxGridView ID="ASPxGridView1" runat="server" AutoGenerateColumns="False" KeyFieldNa...

check value exists in linq

hi., this is my xml file <Persons> <Person> <id>1</id> <Name>Ingrid</Name> </Person> <Person> <id>2</id> <Name>Ella</Name> </Person> </Persons> i am using linq xml. here the id should be auto-generated.. i need to check if the value of node id already exists . if not exists it should create a new id..how t...

Incorrect EntitySet when using foreach instead of select

I've got a very basic database schema and have created a dbml from it. Two tables are related in a one-to-many. (A)1-*(B) ... hence each A gets an EntitySet called "BSet". If I do: foreach (var a in db.A) { Console.WriteLine(a.Name); foreach (var b in a.BSet) { Console.WriteLine(b.Number); } } I find that it prints out t...

linq remove item from object array where property equals value

If i have IEnumberable<Car> list and i want to remove an item from this list based on a property of the car i want something like: list.RemoveWhere(r=>r.Year > 2000) does something like this exist ? i am doing this over and over so i want to avoid copying the list each time to just remove one item ...