linq

VB.NET LINQ join

I have this challenging task in VB.NET LINQ. I have 2 databases from different servers. I cannot link the databases. The data is retrieved from the databases as : DB1 Client_ID Engagement_ID Enabled Description 600 10 True Company1 600 20 False Company2 700 ...

Possible uses for Intersect

I have two queries that produce the same output. One is using the Intersect extension method, the other is a cross join. There are other ways of also doing the same thing such as a cross join or a normal join, so what else can Intersect be used for? int[] intsA = new[] {1,4,7,0,3}; int[] intsB = new[] {2,3,8,9,1}; intsA.Intersect(int...

Returning a custom list class type from LINQ Query - return same type going in that is coming out

I have a custom List (MyCustomList) that implements List(Of MyCustomClass). I want to run a LINQ query against that and return a filtered MyCustomList. Public ReadOnly Property DebitTransactions As MyCustomList Get Return From item In Me Where item.IsDebit = True Select item End Get End Property I ...

LINQ on a DataTable IN a CLR Stored Procedure.

Hi, does anybody know if it's possible (and how) to use LINQ on a DataTable inside a CLR Stored Procedure? I have no problems using LINQ on a DataTable in a standard WinForms proj however; I'm using a Database Project in VS2010 on SQL2005 and creating a Stored Procedure: (simplified listing) [Microsoft.SqlServer.Server.SqlProcedure] ...

Convert nested for-loops into single LINQ statement

Hi, can someone please help me turn this nested structure into a single LINQ statement? EventLog[] logs = EventLog.GetEventLogs(); for (int i = 0; i < logs.Length; i++) { if (logs[i].LogDisplayName.Equals("AAA")) { for (int j = 0; j < logs[i].Entries.Count; j++) ...

Displaying customised data in a datagrid view

I am trying to create an application where I want a data grid view to display the data depending on the date that the user selects in the combo box i.e.cmbDate according to my application. The cmbDate displays the available dates in the database. Below is my source code that I have written but on debugging the compiler gives an error of ...

This is strange in dbml designer Column name and Enttiy Name is different.

You know we are writing codes. on the other hand; we are changing DBML files if add or change database table. i droped my tables and added new tables. My DBML does not include new columns names. in My Database ENG_MAINWP_SELECTED_X is not the same as DBML this column ,n my dbml : ENG_MAINWP_SELECTED_X_ Why this strange behavior occur...

EntityRef<T> Issues, not returning value from Lookup List

Ok, I'll explain this as much as I can... I've got a Site Lookup Column called EEE Content Type which refers to the Site Content Item Type Types List. Now in my custom list (which inherits from Item), I am referencing that column, and it comes up in sharepoint fine and displays the lookup values. The issue is when I'm using SPMetal.ex...

SingleOrDefault throw exception on more than one element

Im getting error whenever i fetch like this Feature f = o.Features.SingleOrDefault(e => e.vcr_LinkName == PageLink && e.bit_Activate == true); because this can return one or more than one element. so what is the alternative approach that i can use to solve this issue ...

Linq to Entity get a Date from DateTime

var islemList = (from isl in entities.Islemler where (isl.KayitTarihi.Date >= dbas && isl.KayitTarihi.Value.Date <= dbit) select isl); It gives error: date is not supported in LINQ to Entities... How can i get date in linq. ...

Search function with unknown indata

Hello everyone! I'd like to make a search function that takes indata from 5 textboxes, Name, gender,ID, animal category and animal. The diffrances between animal category and animal is for eg. animal category = mammal and animal = bear. So these are optional to the user, when he/she hits the button it should search for the given paramete...

Remove items from IEnumerable<T>

i have 2 IEnumerable collections. IENumerable<MyClass> objectsToExcept and IENumerable<MyClass> allObjects. objectsToExcept may contain objects from allObjects. I need to remove from allObjects objects in objectsToExcept. For ex: foreach (var myClass in objectsToExcept) { allObjects.Remove(myClass); } OR allObject.Except(ob...

Dynamically evaluating string conditions in C#

I have a collection of strings. I need to find out from this collection strings which satisfies some condition e.g. that string contains A and B or C. These criteria are specified by the user so they are dynamic. In Linq it should be something like, List<String> items = new List<string> { "sdsdsd", "sdsd", "abc"}; var query = from item...

Aggregate function over an aggregate result set using linq

I have the following linq query: var totalAmountsPerMonth = from s in Reports() where s.ReportDate.Value.Year == year group s by s. ReportDate.Value.Month into g orderby g.Key select new { month = g.Key, ...

Unique list of items using LINQ

I've been using LINQ for a while now, but seem to be stuck on something with regards to Unique items, I have the folling list: List<Stock> stock = new List<Stock>(); This has the following Properties: string ID , string Type, string Description, example: public class Stock { public string ID { get; set; } public string Type {...

How do you tell at run time if an IEnumerable<T> is deferred?

I want to be able to ask, at run time, an IEnumerable if it is a deferred expression or if it is a concrete collection. So, if the method was called IsDeferred, then IsDeferred( myList.Where( i => i > 5 ) ) would return true and IsDeferred( myList.Where( i => i > 5 ).ToList() ) would return false. Thanks. EDIT: I thought I would be a...

How to get Resharper to convert back to a foreach loop

Resharper 5 can convert my foreachloops to Linq queries. Which I like. But linq is way way way harder to debug than a foreachloop. When I convert my foreach statement to a linq query, I don't see any option to go back the other way. Does any one know how to do this? Is it even possible? ...

How can I get LINQ to return the object which has the max value for a given property?

If I have a class that looks like: public class Item { public int ClientID { get; set; } public int ID { get; set; } } And a collection of those items... List<Item> items = getItems(); How can I use LINQ to return the single "Item" object which has the highest ID? If I do something like: items.Select(i => i.ID).Max(); ...

Pass a lambda expression in place of IComparer or IEqualityComparer or any single-method interface?

I happened to have seen some code where this guy passed a lambda expression to a ArrayList.Sort(IComparer here) or a IEnumerable.SequenceEqual(IEnumerable list, IEqualityComparer here) where an IComparer or an IEqualityComparer was expected. I can't be sure if I saw it though, or I am just dreaming. And I can't seem to find an extension...

Queriable variable cannot be found in the context

if(){...} else{...} if ( query.Count > 0 ){...} The displayed above is a skeleton similar to the one that I use. In the first if-then-else sequence I initialize a query variable (used in LINQ) called query and then check it at the next if -statement. Still the environment says that query is not presented in the current cont...