4
votes
2answers
59 views

How to write a dynamic Lambda Expression to access Nth Parent entity?

I have an application using nhibernate and linq to do my queries on database. Everything works fine but I have the follow model mapped (with auto-related): public class A { public virtual int Id ...
1
vote
4answers
60 views

how to validate if lambda query returns null

I retrieve data from database with lambda like var obj = DBContext.MyTable.Where(x => x.ID == 2).SingleOrDefault().MyColumn; Actually , in MyTable , there is no ID with 2 . So I got this ...
10
votes
1answer
254 views

C# Replace all elements of List<string> with the same pattern with LINQ

I have a C# List with thousands of strings: "2324343" "6572332" "45122" ... I would like to replace all of them with brackets around them, so then they would look like "(2324343)" "(6572332)" ...
1
vote
1answer
41 views

How to put a lambda with external parameters into a callback function

I have the following code which basically does what I want: string firstName = "Chuck"; string lastName = "Norris"; filtered = dvds.Where( dvd => (dvd.Element("Actors") != null) ...
2
votes
1answer
46 views

ICollection <T> to string array (using string property)

I have an ICollection of Thing. Thing has a string property Name. I would like to get an array of all Name in my ICollection. I know I can do this by iterating over the collection and building the ...
2
votes
2answers
46 views

lambda inner join and select all

Here is how I inner join in lambda , var myObject = tableNames.Join(tableSchool, x => x.sID , s => s.schoolID , ( (x,s) => new { } ) ).ToList(); I have many fields in both tableNames ...
9
votes
2answers
143 views

What's the story with ExpressionType.Assign?

I was under the impression that assignment was not possible inside a lambda expression. E.g., the following (admittedly not very useful) code Expression<Action<int, int>> expr = (x, y) ...
3
votes
3answers
118 views

Difficulty understanding particular lambda expression

This is a really simple question, I would imagine, for someone who knows lambda well. I am just now learning it and have run across one expression that doesn't make sense to me. From what I ...
1
vote
4answers
75 views

LINQ List.AsParallel with boolean return

I've got a static List<long> primes of all known primes up to a certain point, and a function like this: static bool isPrime(long p) { double rootP = Math.Sqrt(p); foreach (long q in ...
4
votes
1answer
154 views

LINQ Expression Tree Any() inside Where()

I'm trying to generate the following LINQ query: //Query the database for all AdAccountAlerts that haven't had notifications sent out //Then get the entity (AdAccount) the alert pertains to, and find ...
3
votes
6answers
85 views

How to use a lambda expression as a parameter?

I have below method: private List<TSource> Sort<TSource, TKey>( List<TSource> list, Func<TSource, TKey> sorter, SortDirection direction) { ... } and ...
0
votes
1answer
45 views

How to use linq to entities queries or Lists in linq to sql queries

I have a generic EF repository and need to get items from database using nested where statements. var categoryGroups = repository.Categories.Where(a => a.Vehicles.Where(v => ...
2
votes
3answers
64 views

Linq query to group items and query from the top item in each group

So, I have a list that looks something like this. Its basically a state history for a bunch of items, with the most recent state representing the current state. Record Id State Date ...
-6
votes
3answers
71 views

Grouping objects in c# [closed]

I have a problem . I have some objects structured in the way described below: InvoiceItem { name = "Laptop" price = 100$; taxRate = 23% <-- can be 22% 8% etc; quantity = 1; } Invoice { ...
2
votes
2answers
61 views

Dynamic number of evaluations on a where (lambda)

I'm new to Entity Framework, LINQ and lambda expressions. I need to do a search over a user's table, and I need to emulate one that already exists on a desktop application. This search gives only 1 ...
0
votes
1answer
69 views

Dynamic expression for filter IQueryable

I have a situation where I have just the property name (string) and the value by which desire filter. I need to filter the list to return true if any name repeated. Remembering that the filter should ...
1
vote
1answer
44 views

Check null result before accessing property or calling method

I would like to know if there is a better way or general rule to check null result before accessing property or calling method in C# Linq or lambda expressions. Thanks in advance. At my ...
0
votes
1answer
24 views

Linq Query with Join not working on .Net 3.5 but works on .Net 4+

My query was working in .Net 3.5 SP1 until I added a join. The join was put in place to allow selection from the Comments entity even when there was no associated User entity. I get the following ...
0
votes
1answer
31 views

How to write lambda (linq) expression for sql?

I have an Sql statement for which I need go generate corresponding Lambda Expression (Linq). Here is the SQL Declare @CurrentUserId as int Declare @CurrentDate as datetime Set @CurrentDate = ...
0
votes
2answers
94 views

Where clause not entering lambda [closed]

I have the following lambda var entities = JTransformer.Queryer.GetList() .Where(x => { var y = JStubs.GetType(x.Name); return (y.Impliments(baseType) && y.IsGenericType); }); ...
2
votes
4answers
57 views

String building with particular pattern using char separator

I want to have an string in this format name1,date1|name2,date2 For that I have written a method int ifirstStringLength = strFirstStringArray.Length; int iSecondStringLength = ...
2
votes
5answers
81 views

Lambda property value selector as parameter

I have a requirement to modify a method so that it has an extra parameter that will take a lambda expression that will be used on an internal object to return the value of the given property. Forgive ...
6
votes
4answers
100 views

Returning Expression<> using various class properties

I have something like this: public Expression<Func<Message, bool>> FilterData() { switch (this.operatorEnum) { case FilterParameterOperatorEnum.EqualTo: return ...
-5
votes
3answers
139 views

Could C# Linq do combinatorics?

I have this data structure: class Product { public string Name { get; set; } public int Count { get; set; } } var list = new List<Product>(){ { Name = "Book", Count = 40}, { Name = ...
0
votes
2answers
58 views

Expression.Equal - How to Compare Nullable and Non Nullable fields?

I have a nullable datetime field and I have to convert the string date field to a nullable datetime type (using Expression)....I did this using the below. ...
0
votes
1answer
28 views

Generating lambda expression - Type conversion Error

I have a generic method that filters a list of entities, filtering is done by generating lambda expressions: protected object initFilters<TEntity>(string targetEntity, List<SearchItem> ...
0
votes
1answer
28 views

Will there be any performance or quality issues if we use lambda expression in foreach loop?

I have a piece of code as below - var serviceResponseItems = new List<ServiceResponseItems>(); foreach (var item in serviceResponse.SomeItems.Where(x => !string.IsNullOrEmpty(x.Id) ...
2
votes
1answer
48 views

Runtime creation of LINQ expression

Say I have this expression: int setsize = 20; Expression<Func<Foo, bool>> predicate = x => x.Seed % setsize == 1 || x.Seed % setsize == 4; ...
2
votes
5answers
78 views

Remove items from list<a> AND list<b> when a.Foo == b.Bar

I'm looking for an elegant way of comparing 2 different List<> collections and removing the items in which a specific field value matches. For example: Customer object class Customer { ...
0
votes
3answers
74 views

How to query records based on date

I have a DataTable with 5 columns with type of int, string and DateTime. I have written a LINQ query to filter records by date. How do I get records by today and yesterday? var Data = ...

1 2 3 4 5 41
15 30 50 per page