linq

How to use orderby with 2 fields in linq?

hi Say I have these values in a database table id = 1 StartDate = 1/3/2010 EndDate = 1/3/2010 id = 2 StartDate = 1/3/2010 EndDate = 1/9/2010 Now I have so far this orderby for my linq var hold = MyList.OrderBy(x => x.StartDate).ToList(); I want to order it however also using the end date. Like so the order I would want this in a...

WPF LINQ DataContext Refresh not reading new records in the sql database table

I have a LINQ datacontext and a ObservableCollection holding records for a Companys table in SQL Changes to the current records and new records made to the current datacontext (DataDC) are reflected when I do a DataDC.SubmitChanges(); However if I have another Window with a separate DataContext to the same tables, if I modify fields...

Any .NET ecommerce packages using MVC and Linq?

I'm trying hard not to go off and roll my own shopping cart, but after perusing the available .NET ecom packages, it's all ASP.NET webforms. In addition, if i see another handrolled DB layer or some manual invocation of Activator.CreateInstance() for extensibility, i'm going to break out in hives. So what I'm looking for is a shopping c...

How to add LINQ to SQL query results to Observable Collection?

In WPF app I have an Observable Collection which is connected through databinding with ListView. I would like to populate this Observable Collection from LINQ to SQL query, but with no success. In fact my code even doesn't compile (I pointed out the problem lines with comments). The structure of underlying Observable Collection Class i...

How to use PropertyChangedEventHandler of LINQ to SQL class for immediate updating?

In my WPF app I have implemented LINQ to SQL query which populates an Observable Collection connected with ListView. It is in this method which I can call from somwhere and it works OK: private void VisualizeAllShows() { MyfirstdbDataContext context = new MyfirstdbDataContext(); _ShowQuCollection.Clear(); var sh = from p i...

Linq fails instead of returning null?

Hello, I am trying to filter a list of items using the .Where method, and return the first item matching the filter. However if there are no items matching the filter, instead of returning null it throws an exception. Here is the line of code I am using: DescendantNodes.Where(dNode => dNode.InnerText.Contains("rain")).First(); Is t...

Using the magic of LINQ - How to call a delegate for each criteria that matches?

Hi! I wanna do something like this: List<string> list = new List<string>(); ... put some data in it ... list.CallActionForEachMatch(x=>x.StartsWith("a"), ()=> Console.WriteLine(x + " matches!");); Syntax: CallActionForEachMatch(Criteria, Action) How is this possible? :) ...

How to ask "Is there exactly one element satisfying condition" in LINQ?

Hi everyone, Quick question, what's the preferable way to programmaticaly ask "Is there exactly one element in this sequence that satisfies X condition?" using Linq? i.e. // Pretend that the .OneAndOnlyOne() method exists int[] sequence = new int[] { 1, 1, 2, 3, 5, 8 }; Assert.IsTrue(sequence.OneAndOnlyOne(x => x == 2); Assert.IsFalse...

Does LinqDataSource perform Server-Side paging by default?

The title says it all. I've seen hints around the net that this is the case, but I can't find any official documentation to this effect. I want to be sure I have my facts straight before I utilize the LinqDataSource. Thanks guys. ...

Can I update the UI from a LINQ binding?

This little bit of code will help me describe my problem: public class Car { ... } public class CarQueue : ObservableCollection<Car> { public IEnumerable Brands { get { return (from Car c in this.Items select c.Brand).Distinct(); } } } Ok now I have an instance of CarQueue class bound to a DataGrid. When I add...

Updating front-end WPF app from a SQL Server database

Please, help me clear my mind on the following question. Recently I asked a question on SO, about possibility of immediate updating WPF classes from SQL Server DB through LINQ to SQL: http://stackoverflow.com/questions/1991455/how-to-use-propertychangedeventhandler-of-linq-to-sql-class-for-immediate-updatin from the answers I got know...

How to select static text with LINQ query?

I have a listbox and I want its ItemsSource to be all the items of an ObservableCollection + an additional static text such as "All Items." Right now I just have something similar to: listbox1.ItemsSource = from Car c in Cars select c.Model I know I could just manually add the text to the listbox, but I want it...

XML with LINQ without XPath

I have an object structure I have deserialized from XML - but I'm wanting to use it with LINQ. Is there any way I can add this capability to a normal object structure without the hassle of XPath stuff? ...

UPDATE SELECT in LINQ to SQL

I am writing a multithreaded service that picks up jobs to process that has the status of 1 (unprocessed). As soon as they are picked up, I need to change the status of those rows to 2 (indicates In Progress) so that another thread (that is spawned within a few seconds) does not pick up these rows for processing. For select, I would do ...

How can one "scan" a lambda expression in C#?

Is is possible to scan a function provided as a lamba expression to figure out the nature of the function at runtime? Example: class Program { static void Main(string[] args) { Examples example = new Examples(x => x ^ 2 + 2); } } public class Examples { public Examples(Func<dynamic, dynamic> func) { ...

LINQ query finds subclass in an ObservableCollection of base class

I'm still getting my head around LINQ queries and the LINQ extension methods. Say I have a base class BaseA and subclass SubB with a property IsAwesome. I have an ObservableCollection<BaseA>. Is there some neat way I can grab a collection of only SubB classes where IsAwesome is true? ...

how to force sqlmetal to keep field name case?

When dbml file is generated automatically by Visual Studio I get the exact field names as they appeared in the tables. However, since VS does not provide refresh function for dbml, I run sqlmetal manually to re-create dbml file. It works fine with one exception -- sqlmetal "corrects" the names ses_Id -> Ses_Id aga_Id -> Aga_Id and so...

Using Linq to select maximum value in a group

Oh, I just find that the error is caused by another part of code. Case closed. I have 2 tables 1- userinfo id uid name 1 11 Billy 2 22 Paul 3 33 Joshua 2- Score id uid score 1 11 30 2 22 40 3 11 50 4 11 60 5 33 20 6 33 70 7 33 80 I have a class called ScoreUser public class ScoreUser{ public long uid{get; ...

Is it possible to build dynamic LINQ queries to non-strongly type datatables?

Using LINQ, I've been trying to use the System.Linq.Dynamic library in order to query a datatable dynamically. The problem is that it's not strongly typed, and the extension method for select is expecting an IEnumerable as the source. Is there a way to work around this? Example code: var query = dataSet.Tables[0].AsEnumerable().Select...

Entity Framework - Mapping doesn't map for stored procedure?

I have a stored procedure that search a view using full text. I'm trying to map the results to an existing Entity (Sales), where I mapped the column MivType to SaleType (as it makes more sense, and I want to keep db names away from my web site). The stored procedure is mapped to a Function Import, and I've defined its ReturnType to Sales...