Tagged Questions
1
vote
1answer
39 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 ...
7
votes
6answers
190 views
Why I am getting different result from two almost equal expressions to get data from database using Entity Framework context
I am validating username (case-insensitive) and password (case-sensitive) from database
I am using Entity Framework 5.0 to interact with database
In the database password is
...
6
votes
1answer
115 views
How to remove yourself from an event handler?
What I want to do is basically remove a function from an event, without knowing the function's name.
I have a FileSystemWatcher. If a file is created/renamed it checks its name. If it matches, it ...
0
votes
0answers
43 views
ExecuteSqlCommand with Lambda Expressions
We are using repository pattern with unit of work pattern to interact with database.
I have the below method to execute stored procedure:
/*** Execute stored procedure ***/
public virtual void ...
0
votes
2answers
54 views
Left Outer Join using Entity Framework and Lambda Expressions
Employee
id, name, datejoin, deptID
and another table that is
Marketing
id, name, deptID
What I am trying to do is search of deptID from Employee table in Marketing to see if it exists,
if it ...
3
votes
7answers
145 views
How can I make this code faster?? List<custom_class>().Find(lambda_expression)
I need to match email sends with email bounces so I can find if they were delivered or not. The catch is, I have to limit the bounce to within 4 days of the send to eliminate matching the wrong send ...
0
votes
2answers
90 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
56 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
1answer
37 views
Getting Object Property to String Using Lambda Expression
Suppose I have this class:
class MyClass {
public int MyProperty { get; set; }
}
And I want to get the MyProperty as string (e.g. "MyProperty") but through lambda expression or any other way that ...
1
vote
2answers
42 views
Expression.Convert: Object of type 'System.Int64' cannot be converted to type 'System.Int32'
I asked a question yesterday here about reading properties from an anonymous object and writing them to private fields of a class. The problem solved. Here is the short story:
I have some data in ...
0
votes
1answer
33 views
Expression for read from property and write to private readonly field
It is a long story ): I have some types look like this:
public class Model {
private readonly SomeType _member;
private readonly AnotherType _member2;
public Model(SomeType member, ...
5
votes
3answers
181 views
List of Expression<Func<T, TProperty>>
I'm searching a way to store a collection of Expression<Func<T, TProperty>> used to order elements, and then to execute the stored list against a IQueryable<T> object (the underlying ...
2
votes
5answers
78 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 ...
0
votes
1answer
57 views
Using a lambda expression to specify parameter of method
Given the MethodInfo of a method how can I use a lambda expression to specify a parameter (ParameterInfo)?
For example, given the following method signature:
public string DoSomething(int id, int ...
0
votes
1answer
30 views
Get MethodInfo from expression without knowing method signature
I'm trying to pass an expression that describes a method but I want the argument to be strongly typed and I don't want to have to know the method signature or pass the arguments in the expression, ...
6
votes
4answers
97 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 ...
0
votes
2answers
55 views
Expression and delegate in c#
I have below code that is a pseudo-code.
I want to make this function can accept a Expresstion type, compile this expression and invoke it with proper parameters.
public static void ...
0
votes
1answer
46 views
Iterating through two tables/Entities using lambda expression
using lambda expression I am getting a list of records based on date value using Entity Framework, which is working fine.
DateTime expDate=DateTime.Now(+2);
abcEntities se = new abcEntities();
var ...
-5
votes
3answers
135 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 = ...
4
votes
1answer
73 views
Lambdas and type inference
I'm having a bit of trouble understanding the reason behind why the following code is giving me an error:
var funs = Enumerable.Range(0, 10).Select(x => (int y) => x + y);
foreach (var fun in ...
2
votes
1answer
62 views
Why the AsQueryable following by Any leads to select without Where clasue?
I am using Entity framework 4 and I have the following piece of code:
public decimal GetSchoolSuccessRate(EvaluationComparationFilter filter)
{
return this.GetSuccessRate(x => x.TestCampaignId ...
1
vote
2answers
51 views
Why can the c# compiler not resolve the argument types of a lambda expression in a ternary operator? [duplicate]
I have this code:
Action<A, B> fnUpdate = (someBool) ? (a, b) => a.propOne = b : (a, b) => a.propTwo = d;
Why can the compiler not resolve the types of a and b, just because it is ...
0
votes
2answers
48 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.
...
1
vote
1answer
59 views
Scope of string inside lambda
I have an interesting scenario in which I've built a validation checking system that maintains a series of requirements in the form List<Tuple<Func<bool>, string>> where the Func ...
2
votes
1answer
45 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;
...
1
vote
1answer
64 views
Using nested collections of lambda expressions to create an object graph
I am interested in utilizing lambda expressions to create a tree of property selectors.
The usage scenario is that we have some code that does some recursive reflection on an object graph, and to ...
1
vote
1answer
33 views
Any way to know when a variable has been closed over?
So closures in C# are awesome, and expressive and great. Except when they aren't (in particular when you don't mean to close a value over). Are there any tricks, (programming or IDE) to determine when ...
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
{
...
4
votes
2answers
60 views
Dynamically evaluating a property string with Expressions
How do I build an expression that will fulfill the following goal:
public object Eval(object rootObj, string propertyString)
eg: Eval(person, "Address.ZipCode") => return person.Address.ZipCode
...
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 = ...