Translate A Call Of The LINQ Extension Method Select Into A Corresponding Expression Tree?
May 23, 2012
The following LINQ query resp. call of the extension method Select in Visual Basic 2010 is working fine:
Dim qAvSalary = qJobData.Select(Function(e) e.AvSalary) But doing so I am not able to specify the name of property I want the query (e.g. AvSalary) using a string variable. This should be possible if I use a LINQ expression tree. Searching and trying a long time on how to translate the query to a corresponding expression tree was not successful. My final approach is:
[Code]...
View 1 Replies
ADVERTISEMENT
Feb 12, 2010
I have a hashing method whose operations depend on input to the function. Profiling the program has shown that too much time is spent evaluating this hash method. I want to try changing it into an expression tree, so the inner loop checks can be done once.
Here is a simplified version of the function (I undid some obvious optimizations for the example, and took out any input validation):
Private Function Checksum(ByVal inputValues As IEnumerable(Of UInt32),
ByVal declarations As IEnumerable(Of String),
ByVal statements As IEnumerable(Of String)) As UInt32
Dim variables = New Dictionary(Of Char, UInt32)
[code]....
I want to create a function which takes the declarations and statements and outputs a specialized expression tree representing a function which takes an IEnumerable of UInt32 and returns a UInt32.Follow-Up:I succeeded, and the speed-up was ridiculous (an order of magnitude). The main things I had to learn where:Use Expression.Lambda and Expression.Compile to get a delegate you can actually use.The Expression.Block factory method has a 'variables' parameter you (essentially) use to declare locals.Expression.lambda has 'parameters'.If you call Expression.Parameter twice, you're dealing with two different variables (even if their name is the same)! Store the result for later usage. Same for labels, etc.The result of a BlockExpression is the last expression in the block.
View 1 Replies
Nov 28, 2010
translation of the following C# Linq Expression (in VB.NET 2008):
syncContext.Send((obj) => eventToBeFired(this, new EventArgs()), null);
Is used in this subroutine:
private void FireEvent(EventHandler eventToBeFired)
{
if (eventToBeFired != null)
{
[code]....
View 3 Replies
Oct 28, 2011
1) I am begginner to dynamic Linq and having serious trouble creating expression tree after WHERE
say.: items.Category_ID=4
I tried to construct it like: Dim products = From items In mydatacontent.Products
Dim AA As ParameterExpression = Expression.Parameter(GetType(String), "items")
Dim left1 As Expression = Expression.Property(AA, GetType(String).GetProperty("Category_ID")) here is the error Dim right1 As Expression = Expression.Constant("4") Dim BB As Expression = Expression.Equal(left1, right1)
[Code]...
View 2 Replies
Jul 26, 2010
I currently have a View in MVC where I pass a single set of data to the view. However, I've come across a problem where I am having to use a LINQ query within a For Each loop in the View to pull out additional information from a SQL View of data from another DB.
The error I'm getting is Late binding operations cannot be converted to an expression tree.
The particular snippet I'm encountering the error on is:
[Code]...
View 1 Replies
Mar 7, 2011
I have built a database structure that represents a category tree to help classify some of the data we have stored. The implementation is that each record in the Category table has a nullable foreign key back into the Category table to represent the parent Category of this category (one-to-many), essentially allowing for subcategories within a broader parent level. There is a CategoryMembership table that links a record in the Item table to its respective Category (many-to-many). I have created the DBML for this database, and it has a member access structure that includes the following:
[Code]...
View 2 Replies
Feb 2, 2011
I'm using .NET 3.5 In my DataLayer class I have references of System.Core,System.Data.Linq, System.Data.DataSetExtensions. But I cantnot use this feature in Linq query if I have Option Strict ON:
[Code]...
View 1 Replies
Mar 24, 2011
I have two lists declared as follows:
Dim lstDBItems As New List(Of DBItem)
Dim lstAppItems As New List(Of AppItem)
I am trying to do something like this:
I've a function which returns List(Of AppItem):
Function GetAppItems() As List(Of AppItem)
'...
End Function
In the above function I populate lstDBItems and then write the return statement like follows:
Return lstDBItems.Select(Function(x)
dim oItem As New AppItem()
oItem.Property1 = x.DbProperty1
[Code]....
The weird thing is the code compiles, but on rumtime I get a type case error.
View 3 Replies
May 3, 2011
I'm trying to implement multicolumn filtering using LINQ expressions in a class that extends BindingList(Of T). Here is the relevant code:
Public Function GetFilterPredicate() As Func(Of T, Boolean)
Dim expressionList As List(Of Expression) = New List(Of Expression)
For Each item as FilterInfo in _FilterList
[code]....
However, an exception is thrown at the Expression.Call statement. I can't quite figure out the right arguments to supply. As it is now, I am getting this error when I run the code:
InvalidOperationException was unhandled:No generic method 'Equal' on type 'System.Linq.Expressions.Expression' is compatible with the supplied type arguments and arguments. No type arguments should be provided if the method is non-generic.
View 1 Replies
May 22, 2012
For I've tried this:Dim exampleItems As Dictionary(Of String, String) = New Dictionary(Of String, String)
Dim blah = exampleItems.Select (Function(x) New (x.Key, x.Value)).ToList 'error here
But I'm getting a syntax error and all the examples that I've seen are in C#.
View 1 Replies
Dec 3, 2009
Why would I use an extension method instead of just creating non-extension sub or function?
For ex, I could have an extension function called IsNullOrEmptyOrAllSpaces on String, which does a check as its name implies. Or I can write a stand alone function that does the same thing. Other than having the extension show up in Intellisense, is there any advantage? Is a call to the extension quicker/more efficient than a call to a regular function?
View 8 Replies
Mar 16, 2012
I saw this post and I want to know if this is possible in VB. So like extension method, do extension properties exists in VB.Net? Here I've read they do, but cannot find any examples.
View 3 Replies
Sep 16, 2010
Write an overload for every numeric type or if possible constrain a generic extension method to just numeric types.
View 2 Replies
Mar 22, 2012
I want to create an ExpressionTree where a Func(of Vector, Vector, Vector, Vector, Double, Double, Vektor) should be called. So I use
Expression.Call(Forces(0).Function.Method, {Vec1, Vec2, Vec3, Vec4, Double1, Double2})(Vec1-4, Double1-2 are declared as ParameterExpression and Forces(0).Function as Func(of Vector, Vector, Vector, Vector, Double, Double, Vector). But I get an AgrumentException, because Forces(0).Function.Method has seven Arguments. (System.Runtime.CompilerServices.Closure as seventh argument at Index 0).
View 2 Replies
Jul 16, 2010
Extension methods are useful for types that you don't own and can't/don't want to derive from and extend (e.g. reference types and interfaces). Obviously, interfaces should be kept as short and to-the-point as possible, so extension methods for interfaces are particularly useful (e.g. LINQ).For classes, especially classes that you own, they're still useful - but I'm wondering how you determine what should be an extension method or what should be a method in the class itself.Personally, every time I think about it, I keep going round in circles with the following thoughts:If it's useful enough, it should be in the class.It's not part of the core responsibility of the class, it should be an extension method - but if it's useful enough, surely it should be the responsibility of the class...
View 3 Replies
Sep 22, 2010
Some long-gone developer left the following LINQ query behind with no documentation and I'm struggling to understand what it does (and therefore if it's doing it right), either by breaking it into pieces or providing the SQL equivalent?
CODE:
I am struggling in particular with the Group Join and Into TargetMatches = Group pieces:
CODE:
View 1 Replies
Aug 26, 2009
I have a table that contains procedure codes among other data (let's call it "MyData"). I have another table that contains valid procedure codes, their descriptions, and the dates on which those codes are valid. Every time I want to report on MyData and include the procedure description, I have to do a lookup similar to this:
From m in dc.MyDatas _
Join p in dc.Procedures On m.proc_code Equals p.proc_code _
Where p.start_date <= m.event_date _
[Code]....
Is there a way to turn a complex lookup (i.e. a non-trivial join) like this into something SQL can recognize so that I can define it in one place and just reference the description as if it were a field in MyData? So far the only thing I can think of is to create a SQL view on MyData that does the linking and bring that into my data context, but I'd like to try to avoid that.
View 2 Replies
Nov 21, 2010
Im getting some VB.Net Late binding operations cannot be converted to an expression tree. errors, have search here on the site and can only find solutions to the SQL get data code, not to my problem. The error "Late binding operations cannot be converted to an expression tree." At all my x.NAME) lines !? Im new to this so can anyone say me why i get this error..
[Code]....
View 1 Replies
Nov 19, 2010
I get this error "Late binding operations cannot be converted to an expression tree."
At all my x.NAME) lines !?
<div>Navn: <%: Html.EditorFor(Function(x) x.Name)%></div>
<h3>Adresse</h3>
<div>Linje 1: <%: Html.EditorFor(Function(x) x.Line1)%></div>
[Code].....
View 3 Replies
Dec 29, 2011
What I am about to do build is a UI that will allow a power user to build complex queries.
This is non-trivial, but very common. So before I re-invent the wheel, I would like to see if anybody can point me to some already-written free code or release some of their own.
Required:
To be able to specify some 'where-clause' type logic like this: Age>21 and (Citizen=True or HasGreeCard=True) but without having to type the query code, instead, use a UI with constrained options and on-the-fly syntax checking (e.g., no unclosed parenthesis or ending a term with an Operator).
I've seen this type of thing in many line-of-business apps, where you can say 'add condition' and another line appears on the UI like this:
Dropdown of fields Dropdown of ops (=, >, etc) Blank box for entry
And you can add more lines, and the lines are all and'ed, but you can also decide to OR a few, or insert parenthesis (explicity or via indenting), NOT a line, insert, delete, and move lines around, etc.
Not required but nice:
WPF - I could convert from winforms. Extensibility using OO constructs. Validate the sanity of the query. Emit a System.Linq.Expressions expression tree - or similar data structure. If it attempts to execute the query I don't need that; but I don't mind removing it.
View 1 Replies
Nov 12, 2009
Does calling the Dispose method on a Windows.Forms.Timer call it's Stop method? Or should I stop the timer before I dispose it?
View 5 Replies
Apr 26, 2010
I have an extension method written in visual basic as follows:
Imports System.Runtime.CompilerServices
Namespace Parsing
...
Public Module CSVParse
[code]....
Unfortunately the compiler is giving a 'Cannot resolve symbol' error for 'DoVB()' and highlighting it red.Yet it will recognise the call in a static fashion.
CSVParse.DoVB(test);
View 1 Replies
Feb 16, 2010
I will try to explain what I need.Let's say that I have a class like this:
Public Class Example1 Public Sub ToBeCalled()
[Code]...
View 5 Replies
Apr 9, 2011
I have a delete method for a binary search tree. It only deletes the last two entered values. When trying to delete the root or anything to left of it it returns a null pointer exception.
PublicFunction Delete(ByVal key AsInteger) AsBoolean Dim current AsNode = root Dim parent AsNode = root Dim isLeftChild AsBoolean = True While (current.value <> key)
parent = current If (key < current.value) Then isLeftChild = True current = current.rightNode Else
[code].....
View 3 Replies
Feb 10, 2009
Is there any native functionality in VS2008 for generating a call tree? If not, is there any a third party add-in that has this functionality?
View 2 Replies
Apr 10, 2010
I know how to add extension method Like (Date.Now.MyExtensionFunction()),But I can NOT find how to add such methods and functions in class (not in module) with vb.net
View 3 Replies
Mar 26, 2012
I am trying to write extension methods in VB.NET
Imports System.Runtime.CompilerServices
Module ExtensionMethods
<Extension()> _
[code]....
But I am getting this error.Class 'System.Web.UI.WebControls.ListItem' cannot be indexed because it has no default property
What could be wrong?I am calling the code like this.
ddlSalesmanager.Items.FindByText(survey, StringComparison.CurrentCultureIgnoreCase)
P.S: I ported this wonderful code from C# to VB
View 1 Replies
Feb 23, 2012
I converted some code from c# for a VB.net project I have an object declared as this :
<Serializable()> _
Public Class oUserApplication
Public ApplicationID As Integer = 0
Public ApplicationRoleID As Integer = 0
[code]....
View 3 Replies
May 18, 2009
I ran into a strange issue over the weekend while I was working on an asp.net mvc project in vb.net. I created an extension method to convert an integer to the corresponding month it is associated with. I tested the extension method in a console application so I know it is working.
In my asp.net mvc project I have a view and want to call the extension method but I get an error that the extension method is not recognized. I imported the namespace it was contained in and still couldn't shake the error.
Extension Method:
Imports System.Runtime.CompilerServices
Module SiteExtensions
<Extension()> _
[Code].....
View 3 Replies
Nov 10, 2010
I want to implement an extension method in VB.NET that will clone an object of type T.Say, I want
Dim cust1 as New Customer() //...
Dim cust2 as New Customer() //...
cust2 = cust1.Clone()
[code]....
View 2 Replies