linq

Treat multiple IEnumerable objects as a single IEnumerable

Hi, My question seems to be something easy, but I can't figure it out. Let's say I have a "root" IEnumerable of objects. Each object has IEnumerable of strings. How can I obtain a single IEnumerable of those strings? A possible solution is to do: public IEnumerable<string> DoExample() { foreach (var c in rootSetOfObjects) { ...

Using Linq methods causes missing references to DependencyObject in WindowsBase

I have some c# source that I want to compile using CodeDom within my application (for a plugin) Everything works fine, except if I use a Linq extension function on some of my collections var dict = new Dictionary<KeyType, ValueType>(); .... dict.Any(KV=>KV.Key == "Some Key"); When I try to compile source that has this code, it CodeDo...

bind linq expression

Hi, I have a ListView and ObservableCollection in my wpf application. I want to bind linq expression to ListView: lv_Results.DataContext = store.Where(x => x.PR > 5).ToList(); tempStore = new M1Store() { SiteName = siteName, Date = date, ...

How to Solve this Error "Cannot convert lambda expression to type 'string' because it is not a delegate type"

. I get this error: "Cannot convert lambda expression to type 'string' because it is not a delegate type" - keyword select become underlined in blue Can you please advice. Employee emp = new Employee(); comHandledBySQt.DataSource = from x in emp.GetDataFromTable("1") select new { x.Id, Name = x.FirstName + " " ...

I can't understand GroupJoin where i will need it in database relationships.

Hello Everybody I am thinking 5-6 hours to understand something about GroupJoin. I am talking about query with linq for Database tables.I understand what Join and GroupJoin does but I really couldn't understand where i will need it.I feel that Join does all what i will need but if there is something which Join can't without GroupJoin so...

Help with Linq Expression - INotifyPropertyChanged

Hello, I'm reading the source code from the latest Prism 4 drop and am interested in solving this problem. There is a base class for the ViewModels that implements INotifyPropertyChanged and INotifyDataErrorInfo and provides some refactoring friendly change notification. protected void RaisePropertyChanged<T>(Expression<Func<T>> prope...

DefaultIfEmpty doesn't work

Why is array still null after queried by DefaultIfEmpty ? class Program { static void Main(string[] args) { Program[] array = new Program[5]; Program[] query = array.DefaultIfEmpty(new Program()).ToArray(); foreach (var item in query) { Console.WriteLine(item.ToString()); } ...

how to extract Datatable or DataSet from Linq Query or List.

how to extract DataTable or DataSet from Linq Query or List. e.g I have linq query like this MyDBpDataContext dcSp = new MyDBpDataContext(); dcSp.myProgrammSP().ToList(); I wrote an Sp which sends a Table as result and I have code which is already using DataTable So I want to convert this result in DataTable. ...

linq group by with count

Hello, Im trying to write query in linq Select UserId, UserNumber FROM User where UserNumber in (Select UserNumber FROM User group by UserNumber having Count(UserId) = 1) Aby hints ? ...

Parsing google feed with linq to xml

Hi I'm trying to parse XML feed that I get via Google Contacts API with LINQ 2 XML. That's what feed looks like: <feed xmlns="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/" xmlns:gContact="http://schemas.google.com/contact/2008" xmlns:batch="http://schemas.google.com/gdata/batch" xmlns:gd="http:...

Entityframework 4.0 .CreateQuery<T> and OrderBy exception

Hi Guys, I thought this was fixed in 4.0. I have this method public IQueryable<T> All(Expression<Func<T,object>> sort) { return EntityContext.CreateQuery<T>(EntityName).AsQueryable<T>().OrderBy(sort); } this throws the following exception Unable to cast the type 'System.Int32' to type 'System.Object'. LINQ to E...

Is there any extension method which get void returning lamda expression ?

For example int[] Array = { 1, 23, 4, 5, 3, 3, 232, 32, }; Array.JustDo(x => Console.WriteLine(x)); ...

Serious problem with WCF, GridViews, Callbacks and ExecuteReaders exceptions.

Hi, I have this problem that is driving me insane. I have a project to deliver before Thursday. Basically an app consiting of three components that communicate with each other in WCF. I have one console app and one Windows Forms app. The console app is a server that's connected to the database. You can add records to it via the Windows...

How to differentiate between two similar fields in Linq Join tables

How to differentiate between two select new fields e.g. Description c.Description and lt.Description DataTable lDt = new DataTable(); try { lDt.Columns.Add(new DataColumn("AreaTypeID", typeof(Int32))); lDt.Columns.Add(new DataColumn("CategoryRef", typeof(Int32))); lDt.Columns.Add(new DataColumn("De...

Grabbing Just The Top Entry From A LINQ Query

I basically have a lot of poorly designed code to do something that, I'm sure, can be done far more elegantly. What I'm trying to do is grab the last date from a database table. var Result = from a in DB.Table orderby a.Date descending select new {Date = a}; foreach(var Row in Result) { LastDate = Row.Date.Date; break; } Basicall...

How to map LINQ EntitySet to List property in property setter?

In my model I have these entities: public interface IOrder { string Name {get;set;} List<IProduct> OrderedProducts {get;set;} } public interface IProduct {} In partial class generated by linq-to-sql I map these properties on my entity properties: public partial class Order : IOrder { List<IProduct> OrderedProducts { ...

LINQ Joins - Performance

I am curious on how exactly LINQ (not LINQ to SQL) is performing is joins behind the scenes in relation to how Sql Server performs joins. Sql Server before executing a query, generates an Execution Plan. The Execution Plan is basically an Expression Tree on what it believes is the best way to execute the query. Each node provides inform...

Get all referencing columns to a referenced column in linq

Say you have a Table named Sales with a SalesOrderId. Then you have two tables SalesOrderHeader and SalesReport that reference SalesOrderId. Starting from the Sales Tables and SalesOrderId, is there any way to figure out those two table reference it using linq? I want to add a Debug.Assert to my code so that I can update that piece of co...

Delaying LINQ to SQL Select Query Execution

I'm building an ASP.NET MVC site that uses LINQ to SQL. In my search method that has some required and some optional parameters, I want to build a LINQ query while testing for the existence of those optional parameters. Here's what I'm currently thinking: using(var db = new DBDataContext()) { IQueryable<Listing> ...

Can I clone an IQueryable in linq? For UNION purposes?

I have a table of WorkOrders. The table has a PrimaryWorker & PrimaryPay field. It also has a SecondaryWorker & SecondaryPay field (which can be null). I wish to run 2 very similar queries & union them so that it will return a Worker Field & Pay field. So if a single WorkOrder record had both the PrimaryWorker and SecondaryWorker field...