I have a this line of code:
var predicate = Expression.Lambda<Func<TEntityType, bool>>(body, param);
where TEntityType is a generic parm.
However, I don't have generic parm available. I do have:
Type _EntityType;
What is the non-generic syntax for Expression.Lambda is this case?
Thanks
...
I display the contents of a table in the database using a ListBox. Each listbox item is populated with the Text property set to a friendly name, and the Value property set to the unique ID column. The database structure might look similar to the following:
CREATE TABLE GENERIC { FRIENDLY_NAME TEXT, ID INT }
I tried for almost an hour ...
Hi,
In one of the applications we are developing we do lot of XML processing. Currently we use DOM and XPath for most of the processing and we are not much happy with the performance.
At the moment we are considering of moving XML processing logic to LINQ and our initial investigations suggest LINQ performance is much better than DOM....
Hi,
I read http://stackoverflow.com/questions/226127/multiple-single-instance-of-linq-to-sql-datacontext and http://www.west-wind.com/weblog/posts/246222.aspx
I'm developing a web application. In my blclass that has many methods that do some query against the DB, in each and every method, I declare :
Dim db As New DemoDataClassesDa...
Can anyone tell me what the correct Plinq code is for this? I'm adding up the square root of the absolute value of the sine of each element fo a double array, but the Plinq is giving me the wrong result.
Output from this program is:
Linq aggregate = 75.8310477905274 (correct)
Plinq aggregate = 38.0263653589291 (about half what it shou...
I have a LINQ to SQL query:
from at in Context.Transaction
select new {
at.Amount,
at.PostingDate,
Details =
from tb in at.TransactionDetail
select new {
Amount = tb.Amount,
Description = tb.Desc
}
}
This results in one SQL statement being executed. All is good.
However, if I attempt to ret...
public Method1(Expression<Func<T, TProperty>> valueToCompare) {
//Examine expression
}
public Method1(TProperty valueToCompare) : this(x => valueToCompare) {}
and i run them like this
Method1(x => 1);
and
Method1(1);
If i examine the expression when the first overload is called then I get a constant expression. However when ...
I've got a LINQ query that looks like this (at the end):
var query = from myTable0 ...
where myTable1.attributeId == 123 && (bunchaStrings.Contains(myTable1.attributeName)) && myTable2.yesNoValue == 'Y'
When I see the query it turns into this
SELECT ... FROM ... INNER JOIN ... WHERE ... AND (UNICODE([t3].[yesNoValue]) = @p3
So what'...
I am trying to develop some general purpose custom ValidationAttributes. The fact that one cannot create a generic subclass of an attribute is making me nuts.
Here is my code for the IsValid override in a ValidationAttribute to verify that the value of a property is unique:
public override bool IsValid(object value)
{
S...
There are a number of ways to compare strings. Are there performance gains by doing one way over another?
I've always opted to compare strings like so:
string name = "Bob Wazowski";
if (name.CompareTo("Jill Yearsley") == 0) {
// whatever...
}
But I find few people doing this, and if anything, I see more people just doing a straig...
The error message is "The type or namespace name 'T' could not be found."
???
public static Expression<Func<T, bool>> MakeFilter(string prop, object val)
{
ParameterExpression pe = Expression.Parameter(typeof(T), "p");
PropertyInfo pi = typeof(T).GetProperty(prop);
MemberExpression me = Expression.MakeMemberAccess(pe, pi);
...
I'm trying to take the final solution from Phil Haack here and sort using his killer LINQ query but instead of using data context like he is, I want to query against IEnumerable(Of T) ... not having any luck.
Public Function DynamicGridData(ByVal sidx As String, ByVal sord As String, ByVal page As Integer, ByVal rows As Integer) As Acti...
Hi,
I cannot find a way to make this work and hoping someone has an idea. A simplified example would be having a list of say integers 1-100, i want to group every 3 rows so the result would be 1,2,3 in first group then 4,5,6 in next group etc. I know how to get every nth record but what I need is all the records so I can then aggregat...
Hello, I'm a bit of a LINQ newbie and I was having some trouble with the following. I'm trying to perform a query using LINQ on an XML file and store the results in a list of DataClass objects that match the XML.
I've got an XML file that is defined like this:
<NewDataSet>
<NewDataTable>
<Field>Accepted ASNs</Field>
<Va...
Ok this is kinda a messy query and I am only having limited success with it. I have a list of a Foo class that has a datetime property and other data. I have a class/row for allmost every minute, with some missing and some entire days missing like a holiday or weekend. My goal is to group each day for all rows from a start time to an ...
I have a database with this two tables
ProductCategory
IDCat
Name
Description
ProductSubCategories
IDSub
Name
IDCat
This tables are related trought IDCat.
How can i do with LINQ to retrieve the list of Category and SubCategory grouped by Category ??
In my PartialView I would like create a menu with Category and SubCatego...
I develop a reporting engine where reports are based on templates. Every template has string with SQL query and every report has specific values for SQL query parameters. To render a report I set parameters and call DataContext.ExecuteQuery method to get list of records. But to catch returned columns I have to know their names and have a...
Suppose I have the two following Linq queries I want to refactor:
var someValue1 = 0;
var someValue2= 0;
var query1 = db.TableAs.Where( a => a.TableBs.Count() > someValue1 )
.Take( 10 );
var query2 = db.TableAs.Where( a => a.TableBs.First().item1 == someValue2)
.Take( 10 );
Note that only the Where ...
Hi folks,
i've got an IList<Foo> and I'm trying to serialize it as Json without the field names included in the result. As such, i'm trying to create an anonymous object, which i pass to the Json serialization method.
Foo is defined as (pseudo code):-
public class Foo
{
public int X;
public int Y;
}
When i return this as Jso...
Is it possible to flatten a one-to-many relationship using dynamic LINQ?
For example, I might have a list of Users and the User class contains a list of many UserPreferences. The UserPreference class is essentially a name/value pair.
A user will define what types of user preferences are available for a group of users.
public class U...