I'm trying to get the latest x entries in chronological order.
currently I'm doing:
var query = db.OrderByDecending(x => x.date).Take(x).OrderBy(x => x.date)
It seems crazy to be sorting in one direction, limiting and then sorting in the other. Its not like what I'm currently using is causing me sleepless nights, I just wonder whether...
I have 3 tables in my database
Country
City
House
Country table looks like
CountryID
Name
City table looks like
CountryID
CityID
Name
House
CountryID
CityID
HouseID
Name
I use LINQ to SQL and the above tables become classes and have their properties etc.
Now I have my own abstract class called
Location
And cr...
I've got a simple class defined as:
public class IndexEntry
{
public bool HighScore { get; set; }
public List<IndexEntry> SubEntries { get; set; }
//Other properties, etc...
}
I now need to search through a List to find the one item that has its HighScore Property set to true. Since it isn't a flat list, but a Hierarchy whic...
I am new to System.Action<T> and Lambda expression. Here is one case I would like to use.
using System;
using System.ComponentModel.Composition;
public class MyClass {
public static CompositionContainer Container = new CompositionContainer();
private void Initialize(Action<CompositonBatch> action) {}
public MyClass() {
...
I have the following code:
IEqualityComparer<WorkItem> comparer =
new LambdaComparer<WorkItem>((item1, item2) => item1.Type == item2.Type);
var someVar = Pad.Distinct(comparer);
(The idea is to get 1 of each type)
And it is giving the following error message:
The type arguments for method 'System.Linq.Enumerable.Distinct
(Sy...
If have a class of Widgets like this:
public class Widget
{
public double Price { get; set; }
public string Type { get; set; }
public int ID { get; set; }
public string Name { get; set; }
}
And create a list of them:
List<Widget> Widgets = new List<Widget>
{
new Widget {ID = 1, Name = "One", Price = 3.00, Type =...
Hi All,
We have a requirement to provide user friendly descriptions for types. We have a created a resource file which maps the type to a description.
The full name of the instance with the dots replaced with underscores is used as the key.
The description is a string and contains templates that refer to property in the instance.
...
Sorry to bump with a side-question, but although the bug reports indicate them as fixed I still cannot get any of the code to work, crash and all. Have I installed the final release incorrectly or are they still not publicly fixed? :(
I've run into a strange problem. The following simplified code reproduces the problem in MSVC 2010 Be...
Possible Duplicate:
How do I pronounce => as used in lambda expressions in .Net
Sometimes, when helping another programmer write code, I dictate what I want them to type in. Sometimes this can be a frustrating exercise until the programmer gets used to how you verbalize code (i.e. "assign 5 to x" versus "x equals 5"). One thin...
Let's say you have a Generic Class which have a List<T> Items;
Now think of this basic lambda expression:
var result = Items.FindAll(x => x.Name = "Filip");
This will only work as long as we Know the Properties of T, which you don't when it's a generic type.
Therefore I would like to fetch the properties using Reflection like this:...
Hi,
I have a string array Array1 and a string array A2. I want to combine these in a 3rd array A3 but excluding duplicate values. Can this be done through lambda expressions or only through iterating through the array and checking array.Contains()?
Thanks.
...
One of the cool new C++ features in Visual Studio 2010 are lambda expressions. However, I can't get them to work within a managed class.
class UnmanagedClass {
void Foo() {
// Creating empty lambda within unmanaged class.
// This compiles fine.
auto lambda = [](){ ; };
}
};
ref class ManagedClass {
v...
I have inherited a small scripting language and I am attempting to port it to the DLR so that it is a little easier to manage. So far it has been fairly straight forward. I have run into a problem though attempting to dynamically call members of a variable. The current language runs on .NET and uses a parsing loop and reflection to do th...
I have a grid (not data grid) in Silverlight that I build in memory.
I want to be able to pass the grid to a method that will return a parent grid with multiple child grids containing the children in the original grid. The method should split the original grid up into multiple grids whenever the total height of the children in the grid...
Hi Guys. I have a linq question (linq to sql). I have the following peice of code which works fine;
var queryx = (from sa in d1.SampleAttributes
where nodeTable.ToList().Distinct().Contains(sa.client_post_code_prefix)
select sa.SampleId).Distinct();
Note: nodeTable is of type IQueryabl...
I have an object which has a property that contains an IEnumerable of objects. Each object in the IEnumerable has a property that is also an IEnumerable. I am attempting to capture a larger list of the inner property. Unfortunately, the lambda expression that I am using is returning an OrderedEnumerable. I'd like to just retrieve a simpl...
I find myself doing this sort of thing quite often:-
EventHandler eh = null; //can't assign lambda directly since it uses eh
eh = (s, args) =>
{
//small snippet of code here
((SomeType)s).SomeEvent -= eh;
}
variableOfSomeType.SomeEvent += eh;
Basically I only want to attach an event handler to listen for one shot from...
I have 2 tables; they have a many-to-many relationship. One is called Blog the other is Tag.
A Blog can contain a List of Tag objects. How can I go about getting all blogs that have a passed in tag name using lambda expressions?
Thanks!
...
Hi,
I've created an extension method that works just like I wanted. I've noticed that somehow the party and property parameters are 'copied' into the lambda expression. This way I do not need to maintain a custom list of editor/party/property associations.
However, I need to reset the ButtonEdit's ButtonClick event. Since this one is a...
In my quest to understand the very odd looking ' => ' operator, I turned to StackOverflow first. But, alas, I couldn't find anything that really tutorialized lambdas. I wouldn't normally pick up a book that insults the student - certainly, if we are hungry for knowledge, we are not dummies. However, I have found a good place to start, an...