How can I build in wildcards to my LINQ To SQL lambda expression?
This is what I have currently:
var query = from log in context.Logs select log;
foreach (string filter in CustomReport.ExtColsToFilter)
{
string tempFilter = filter;
query = query.Where(Log => Log.FormattedMessage.Contains(tempFilter));
}
This works fine up unt...
Here is my dataset:
1 David
2 David
3 Marc
4 Marc
5 Marc
6 Marc
7 Marc
8 Marc
9 Marc
10 Marc
11 Marc
12 Marc
13 Marc
14 Marc
15 Marc
This query returns 2 records (correct):
query = query.Where(Log => SqlMethods.Like
(Log.FormattedMessage, "%<key>Name</key><value>David</value>%"));
This query returns 2 records (correct):
qu...
I happened to find myself having a basic filtering need: I have a list and I have to filter it by an attribute of the items.
My code looked like this:
my_list = [i for i in my_list if i.attribute == value]
But then i thought, wouldn't it be better to write it like this?
filter(lambda x: x.attribute == value, my_list)
It's more rea...
I am trying to find out if there is an actual computational benefit to using lambda expressions in c++, namely "this code compiles/runs faster/slower because we use lambda expressions" OR is it just a neat development perk open for abuse by poor coders trying to look cool?
Thanks.
PS. I understand this question may seem subjective but ...
I have the following XML:
<PerformancePanel page="PerformancePanel.ascx" title="">
<FundGroup heading="Net Life Managed Funds">
<fund id="17" countryid="N0" index="24103723" />
<fund id="81" countryid="N0" index="24103723" />
<fund id="127" countryid="N0" index="24103722" />
<fund id="345" countryid="N0" i...
Hi,
How can i convert a IQueryable Expression Tree to a Expression<Func<T,bool>> Expression.
IQueryable<Book> Books;
var query = Books.Where(p => p.Author.AuthorId == 5);
Expression<Func<Book, bool>> expression = ?????
...
Is there any particular reason? Is it not possible at all or is it just not implemented yet? Maybe there are any third-party addins that allow lambda evaluations?
UPDATE:
I've found this project on codeplex Extended Immediate Window. Seems that it has been abandoned for some time, but this can be a proof of a concept. Does anybody know...
Whilst putting together a T4 template I threw in a simple lambda expression:
<#=string.Join(",", updateFields.ConvertAll(field => field.Name).ToArray())#>
This causes the template to fail to generate with the error:
Compiling transformation: Invalid expression term '>'
On the line with the lambda expression.
This has been check...
I've been trying to use ILMerge to merge assemblies in VS2010 and the resulting primary assembly ends up being unusable. This only seems to occur when the assemblies being merged contain methods with Lambda expressions. Also, it seems to work fine in VS2008. I've outlined my investigation in more detail at http://tinyurl.com/38mz4ef
...
Probably something simple, but as I'm new to lambda expressions, the problem evades me:
m => m.contactID == contactID && m.primaryAddress == true && (m.addressTypeID == 2 || m.addressTypeID == 3)
I tried to use that lambda expression but I receive an invalid operator. Is there a way to simplify this so that it would work?
Edit:
The ...
I'm not even sure if this is possible, but I've exhausted all of my ideas trying to figure this out, so I figured I'd send this out to the community and see what you thought. And, if it's not possible, maybe you'd have some ideas as well.
I'm trying to make an Attribute class that I can add to a method that would allow me to use a lambd...
I am trying to create a pageing and sorting object data source that before execution returns all results, then sorts on these results before filtering and then using the take and skip methods with the aim of retrieving just a subset of results from the database (saving on database traffic). this is based on the following article:
http:/...
We're trying to make it easy to write strongly-typed code in all areas of our system, so rather than setting var sortColumn = "FirstName" we'd like to say sortOption = (p => p.FirstName). This works great if the sortOption is of type Expression<Func<Person, object>> (we actually use generics in our code but that doesn't matter). However,...
I've been trying to figure this out all night, but I guess my knowledge of the .Net Framework just isn't that deep and the problem doesn't exactly Google well, but if I can get a nod in the right direction I'm sure I can implement it, one way or another.
I'd like to be able to declare a property decorated with a custom attribute as such...
Hi All,
I have a quick linq question. I have a stored proc that should return one row of data. I would like to use a lambda to build an object. Here's what I'm currently doing which works, but I know I should be able to use First instead of Select except I can't seem to get the syntax correct. Can anyone straighten me out here? Thanks f...
This is a bit of noob question - I'm still fairly new to C# and generics and completely new to predicates, delegates and lamda expressions...
I have a class 'Enquiries' which contains a generic list of another class called 'Vehicles'. I'm building up the code to add/edit/delete Vehicles from the parent Enquiry. And at the moment, I'm sp...
Hello!
You have list of objects each of them have id property.
Here's my way to covert it to dict where keys are ids and values are objects:
reduce(
lambda x,y: dict(x.items() + { y.id : y}.items()),
list,
{}
)
Suggest better way to do it.
...
Recently I wrote a piece of C# code utilizing a Lambda expression:
var dynMenu = new List<MenuItem>();
// some code to add menu items to dynMenu
if (!dynMenu.Any(x => x.Text == controller))
{
// do something
}
While going thru my code, I discovered that each MenuItem itself has a property called ChildItems which happens to be of ...
Danny initially asked this question in response to a recent Scott Hanselman post:
Who can tell me what's this :
Func<Customer, bool=""> A optional
parameter with default value? A empty
string for a bool? I replace it with
Func, and get the
different result in my machine!
Everything works well, I get "where"
statement wi...
I have ObservableCollection<ViewUnit> _myItems field, where ViewUnit implements INotifyPropertyChanged.
ViewUnit has Handled : bool property.
The main view of WPF application has a ListBox which binds to _myItems.
I want a separate view of non-handled items only, that is, to have an IObservableCollection<> depended on existing _myItem...