Hi there,
I have a collection of objects and need to take batches of 100 objects and do some work with them until there are no objects left to process.
Instead of looping through each item and grabbing 100 elements then the next hundred etc is there a nicer way of doing it with linq?
Many thanks
...
I have an extension method to dynamically filter Linq to Entities results using string values. It works fine until I use it to filter nullable columns. Here's my code:
public static IOrderedQueryable<T> OrderingHelperWhere<T>(this IQueryable<T> source, string columnName, object value)
{
ParameterExpression table = Expression.Paramet...
Hi folks,
I'm trying to filter a list of objects using linq. When i filter by a Contains(someSearchQuery) it's like it's being case sensitive .. meaning i miss some results.
I have an IList<Foo>'s which has a number of properties, but one is public string MyText { get; set; }
Now, i'm trying to return a IQueryable of Foo's where the...
I need to use linq in C# Windows form application working with .Net Framework 2 not 3.5 . I Know it may be some sort of stupidity to do that. but i need that for some special reasons. Can i import just linq libraries to my project by anyway ? or there is no way except for using 3.5 ?
...
I have a XML file, like this:
<?xml version="1.0" encoding="utf-8" ?>
<ROOT>
<NAME>
ItemName
</NAME>
<LIST>
<ITEM>
ListItem1
</ITEM>
<ITEM>
ListItem2
</ITEM>
<ITEM>
ListItem3
</ITEM>
</LIST>
</ROOT>
How can I use LINQ to get all the ITEM...
Possible Duplicates:
Lambda Expression using Foreach Clause
Why is there not a ForEach extension method on the IEnumerable interface?
This seems pretty basic. I'm trying to iterate over each object of an IEnumerable. It appears that I would have to cast it to a list first. Is that right? It seems to me there should be an ext...
I'm trying to refactor some slow running code which writes XML using nested loops of several datatables. I read that using linq to write the xml would be faster. I'm not well versed in linq, so I was hoping to get some help here.
Some things I need to mention is that the current architecture uses a webservice which returns data to us in...
I have a database return result which has flatten results like below. I want to use Linq to break the flat results into primary classes with the items populating the primary class items property collection.
public class Result
{
public string PrimaryKey { get; set; }
public string Status { get; set; }
public string ItemName { get; s...
I was looking through the sample LINQ queries provided with LINQPad taken from the C# 4.0 in a Nutshell book, and ran across something I have never used in LINQ to SQL... Compiled Queries.
Here is the exact exmaple:
// LINQ to SQL lets you precompile queries so that you pay the cost of translating
// the query from LINQ into SQL only o...
I have not found a clear comparison of what is supported with the NHibernate 3.0 LINQ Provider compared to using the QueryOver syntax. From the surface, it seems like two large efforts into two very similar things.
What are the key trade offs to using each?
...
I've got a list of timestamps (in ticks), and from this list I'd like to create another one that represents the delta time between entries.
Let's just say, for example, that my master timetable looks like this:
10
20
30
50
60
70
What I want back is this:
10
10
20
10
10
What I'm trying to accomplish here is detect that #3 in the ...
I have a class called Structure:
public class Structure
{
public int StructureId { get; set; }
public Structure Parent { get; set; }
}
As you can see, Structure has a parent Structure. There can be an indefinite number of structures within this hierarchy.
Is there any way, using LINQ (with Entity Framework), to get the top-mo...
if I have a structure like this:
Batch Amount
76 495.4
76 975.75
76 25
76 442.46
77 1335.12
77 2272.37
77 34.5
77 496.99
77 360
77 13
77 594.6
And I want to get something like
Batch Amount
76 1938.61
77 5106.58
How the expression should be?
I started with something like:
batches.GroupBy(x => new { Batch = x.Ba...
What could be causing this error:
NullReferenceException was unhanded, Object reference not set to an instance of an object.
var LinqResult =
from a in Db.Table
select new {Table = a};
if(LinqResult.Any())
{
//Blah blah blah
}
...
Hi,
I have a collection like this,
Class Base{}
Class A : Base {}
Class B : Base {}
List<Base> collection = new List<Base>();
collection.Add(new A());
collection.Add(new B());
collection.Add(new A());
collection.Add(new A());
collection.Add(new B());
Now I want to sort the collection based on type (A/B). How I can do this? Please he...
I have the below LINQ to SQL method that takes an inordinate amount of time to execute yet its SQL counterpart is quite simple and fast. Am I doing something wrong in the LINQ part? I am just trying to return some data to display, read-only, in a Data Grid.
I understand that if the tool doesn't fit don't use it and as such I could j...
I have an SQL table with the following design:
TableSchedule:
Id
Description
ImportedDate
I can import a large number of items and they will all have the same ImportedDate.
How can I write a LINQ query that grabs only the entries with the most recent ImportedDate?
var ResultSchedule =
from a in Db.TableSchedule
where a.Impor...
First of all some notes:
1. As I realize I'm asking for relatively a lot, I shall offer a (humble 50 rep) bounty ASAP, even if I'll get an answer before doing that.
2. I'm noob at this, so any direction would help.
3. I'd like only Linq2Sql designer or association properties solution, as it seems most elegant.
4. this is a follow-up ques...
I have made my custom In extension method as shown below:
public static class ExtensionMethods
{
public static bool In(this string str, IEnumerable<String> list)
{
foreach (var s in list)
{
if (s.Equals(str)) return true;
}
return false;
}
...
I am working in LINQ to SQL, ASP.NET MVC, and C#. I have a repository called genesisRepository to connect to the database.
I have a table represented in an object called Stream. It is defined like this:
[Table]
public class Stream
{
[HiddenInput(DisplayValue = false)]
[Column(IsPrimaryKey = true, IsDbGenerated = true, AutoSync...