linq

Linq to Sql query with multiple aggregations

Hi, Given a simple schema e.g. PurchaseOrders { OrderId, Total, LineItemCount }, I want to generate a simple query for some simple stats like below: select sum(lineitemcount) as totalitems, sum(total) as totalsales from purchaseorders However in Linq to Sql I am struggling to get this into one query. At the moment I have this: deci...

Linq-to-Sql: Use LinqDataSource to programmatically retrieve data

I'm using a LinqDataSource to populate a basic GridView in ASP.NET. The user has the ability to filter the results, so I use a few WhereParameters and the Where within the LinqDataSource. My client has requested an option to export the filtered results to a file. Easy enough to pipe the data into a file, but I would prefer not to rewrit...

Linq Matching Pattern

I have to search a list of strings in CityList and if it contains all search strings then it should return true otherwise false. When i search "London","Dallas" against CityList it should return false,because "Dallas" is missing in CityList. var CityList=new string[] { "London","Paris","Houston","Mexico","Budapest"} var search =new s...

Linq filter collection with EF

Hi, I'm trying to get Entity Framework to select an object and filter its collection at the same time. I have a JobSeries object which has a collection of jobs, what I need to do is select a jobseries by ID and filter all the jobs by SendDate but I can't believe how difficult this simple query is! This is the basic query which works: ...

LINQ statement All checks syntax problem

I'm trying to figure out why it does not liking my checks in the All(): itemList.Where(x => itemList.All(x.ItemType != ItemType.Test1 && x.ItemType != ItemType.Test2)).ToList(); The type arguments for method 'System.Linq.Enumerable.All<TSource>(System.Collections.Generic.IEnumerable<TSource>, System.Func<TSource,bool>)' cannot be i...

How to create a dynamic linq query for filter based on ria service?

Suppose I have a table Person(PersonID, Name, ....). Then I use EF to create a Entity model and then create DomainService based on Ria Service. At client side(sliverlight), I try to create a dynamic linq for filter function. What I did is: q = EntityQuery<MyData.Person> q = q.Where(p=> p.Name.Contains(NameVar)); That is fine. Then I h...

fancy way to load contents of a CSV file into a dictionary<string,string> in C#

I know how to do this via streamreader and read to the end of line, but was curious if there was a fancier way of going it (for the sake of learing). filename: blah.csv File layout is simple: "Some234234 ", 234 "blahblha234234 ", 2322 I want to load this into a dictionary (the second part should be a int, but I will pars...

call a function for each value in a generic c# collection

I have a collection of integer values in a List collection. I want to call a function for each value in the collection where one of the function's argument is a collection value. Without doing this in a foreach loop... is there a way to accomplish this with a lambda/linq expression? something like... myList.Where(p => myFunc(p.Value));...

Linq to sort lists of different kind

I am trying to make a log viewer displaying events from different sources but ordered by a time stamp. I have a felling I can use C# Linq for this but how ? example: I have one list of events read from files into a strig list sorted by a datetime stamp. Another source of events are database inserts for which I use Linq to extract the...

Linq: {"Operation could destabilize the runtime."}

In my App i when debuging a have this exception: {"Operation could destabilize the runtime."} in the foreach loop: foreach (var item in Model) when i hover the model in debugmode the first time i says : ResultView=>Expending the result view will enumarate the enumarable base=>Operation Could not destabilize the runtime...

Deleting bulk objects in DataContext

Can't i delete bulk objects like List<Person> prn = new List<Person>(); prn.Add(new Person { Id = "P007", name = "Andrew"}); prn.Add(new Person { Id = "P009", name = "Bernold"}); prn.Add(new Person { Id = "P010", name = "Hare"}); PersonDB.Persons.DeleteAllOnSubmit(prn); PersonDB.SubmitChanges(); I receive error Cannot remove an entit...

Linq to LLBLGen query problem

Hello, I've got a Stored Procedure and i'm trying to convert it to a Linq to LLBLGen query. The query in Linq to LLBGen works, but when I trace the query which is send to sql server it is far from perfect. This is the Stored Procedure: ALTER PROCEDURE [dbo].[spDIGI_GetAllUmbracoProducts] -- Add the parameters for the stored procedure...

Translating Sql to Linq

How to translate select *from ( select EmployeeID,FirstName,LastName,Region from Employees where city in ('London','Seattle') ) x where x.Region is not null into Linq Equivalent. I tried (But null values also get selected) LinqDBDataContext Context = new LinqDBDataContext(); var query = from emps in ...

C# Sql to Linq checking multiple cases

How to check multiple cases in Linq ( to classify "over paid","under paid","medium pay") Sql select id,name,salary, case when salary <=1500 then 'under paid' when salary >=3500 then 'over paid' else 'medium pay' end as status from Person Linq var q = context.Persons. Select(c => ...

Grid data not updating based on text typed in TextBox

Hello I have this lambda expression Me.SubcriperGrd.ItemsSource = _ source.Where(Function(p As subscripers) p.Navn Like navn) where i should filter the grid data based on the typed input in a txtbox It returns the result when i type the full name but it doesn't filter the data as i type along in the txt field what am i missin...

C# Specifying orderby in extension method

How to specify descending in extension method var qry=from p in context.Persons orderby p.salary descending select p; extension method var qry=context.Persons.OrderBy(c=>c.salary); ...

Using Attach with Linq To Sql and Stored Procs

Hello, I am trying to use the attach method to update an entity that was retrieve via a stored proc. The stored proc is set up to return a specific instance, which is present in my dbml. The retrieval works as expected and returns a fully populated object. The reason I need to use a stored proc is that I need to update a property on t...

Send E-mail reminder with ASP.NET

Hi, I have a book lending system written with ASP.NET, VB.NET and LINQ to SQL. I want the web app to send the e-mail reminder about the due date to the borrower before the book is over-due. Should I write a desktop app to check the due date or there's another way around to send e-mail reminder? Thank you for any suggestion. ...

C# LINQ - Retrieve multiple attributes from single element, convert to structured (non-xml) text

Hello all. I have an XML file with property groups and properties. I want to retrieve the property groups, print the Name attribute from that element, and then print the child properties of said property group below that entry. Example XML file: <?xml version="1.0" ?> <XMLDocument xmlns:ns="http://www.namespace.com/ns"&gt; <ns...

C# Linq finding value

I want to return the depart number that is not found Employee Table by comparing Department table. Person Table ID name salary job commision DeptID -------------------------------------------------------------- P001 Jon 2000 Manager NULL 1 P002 Skeet 1000 Salesman 2000 1 P003...