Writing Lamdba Query Expressions Using Linq To Sql Provider?

Jan 30, 2010

how to create a lamdba expression instead of using a regular comprehension linq queries. All of the examples i see are not query a database using linq to sql. i want to able to construct a lambda expression that get my the orders from the northwind database where the country equals "us". I know how to construct this using the standard linq query, but just not using lambdas in vb.net.

View 1 Replies


ADVERTISEMENT

VB Dynamic Run-Time Query With Linq And Lambda Expressions

Mar 16, 2009

I have an untyped dataset returned from my WebService. The user wants to dynamically construct a query referencing tables and columns and specifying values to test for.I have looked at Lambda Expressions and the Expressions.Expression Namespace. I think these provide the answer I'm looking for, but I'm not certain how to go about contructing the linq expressions to extract the datarows I'm looking for.

I plan on limiting the result to one datatable that the query will result in and i"ll provide the joins from the user's constructs.For a simple example I have a DataTable with (n) rows called "Table", and in it there is a computed column called "b_IsActive" that has the expression "Convert(IsActive, 'System.Boolean')". The user wants to retrieve all rows in "Table" where field "b_IsActive" is true.

View 5 Replies

.net - Linq Expressions With Linq To Entities?

Feb 28, 2012

The pattern I'm trying to avoid is checking if a string (normally a control's text value) is null/empty, and if it is, comparing it using Contains to a field in my data. Obviously the field isn't hard-coded into my extension, neither is the object type.What I've got works perfectly in Linq to Objects, but I get the generic run-time error "LINQ to Entities does not recognize the method 'System.String Invoke(GenericQueryHelper.Customer)' method, and this method cannot be translated into a store expression." when using an entity framework model.

Here's what I have:

<System.Runtime.CompilerServices.Extension()>
Public Function CompareAndFilter(Of T)(source As System.Linq.IQueryable(Of T), expressionField As System.Linq.Expressions.Expression(Of System.Func(Of T, String)), compareTo As String)

[code]....

I want my usage to look something like this:

Dim results = repository.Customers.CompareAndFilter(Function(c) c.FirstName, searchText)

I do need to get this running against a SQL database really, as it is filtering results, so I don't want to be doing that in memory.

View 2 Replies

C# - Select` And `sub` Have Brackets Around Them In VB Linq Expressions?

Jul 12, 2011

I converted the following query from C#:

src.Select((c, i) => src.Substring(i)).Count(sub => sub.StartsWith(target))

To the VB.NET query:

src.[Select](Function(c, i) src.Substring(i)).Count(Function([sub]) [sub].StartsWith(target))

Using Developer Fusion. I was just wondering why the VB.NET version has [] throughout.

View 3 Replies

LINQ Query Is Enumerated - Turn On Some Kind Of Flag That Alerts Me Each Time A LINQ Query Is Enumerated?

Sep 22, 2009

I know that LINQ queries are deferred and only executed when the query is enumerated, but I'm having trouble figuring out exactly when that happens.Certainly in a For Each loop, the query would be enumerated.What's the rule of thumb to follow? I don't want to accidentally enumerate over my query twice if it's a huge result.

For example, does System.Linq.Enumerable.First enumerate over the whole query? I ask for performance reasons. I want to pass a LINQ result set to an ASP.NET MVC view, and I also want to pass the First element separately. Enumerating over the results twice would be painful.It would be great to turn on some kind of flag that alerts me each time a LINQ query is enumerated. That way I could catch scenarios when I accidentally enumerate twice.

View 3 Replies

.net - LINQ Dynamic Method Call Using Expressions?

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

Dynamic Property Setter With Linq Expressions?

Jan 5, 2011

I want to create a simple function that does the following:

Sub SetValue(Of TInstance As Class, TProperty)(
ByVal instance As TInstance,
ByVal [property] As Expression(Of Func(Of TInstance, TProperty)),

[code].....

View 1 Replies

Linq - Order By Multiple Columns Using Lambda Expressions

Nov 16, 2009

I'm still trying to get my head around the whole "Lambda Expressions" thing.

Can anyone here give me an example ordering by multiple columns using VB.Net and Linq-to-SQL using a lambda expression?

Here is my existing code, which returns an ordered list using a single-column to order the results:

Return _dbContext.WebCategories.OrderBy(Function(c As WebCategory) c.DisplayOrder).ToList

Note: The WebCategory object has a child WebPage object (based on a foreign key). I'd like to order by WebPage.DisplayOrder first, then by WebCategory.DisplayOrder.

I tried chaining the order bys, like below, and though it compiled and ran, it didn't seem to return the data in the order I wanted.

Return _dbContext.WebCategories.OrderBy(Function(c As WebCategory) c.DisplayOrder).OrderBy(Function(c As WebCategory) c.WebPage.DisplayOrder).ToList

View 2 Replies

Book Recommendation With Good Lambda Expressions And LINQ Chapters?

May 20, 2009

I'm looking for an advanced level VB.NET book which covers LINQ and Lambda Expressions.Generally I read C# .NET books due to lack of good VB.NET books when it comes to generic .NET Framework related subjects. However Lambda and LINQ is quite different in C# and VB.NET I'm looking for an advanced level VB.NET book on this subjec

View 1 Replies

.net - ActiveRecord Linq/NHibernate Linq Not Building Query Completely?

Jul 14, 2011

given this function:

Public Function Search(ByVal StartIndex As Integer, _
ByVal MaxResults As Integer, _
ByVal AccountNumber As String, _
ByVal LastName As String, _

[Code]....

instead of what I expected:

Select count(*) from remitline where lastname = "smith"

What am I doing wrong building up the where clause? I'm using Castle ActiveRecord 2.1

View 1 Replies

Performance Gain In LINQ Query Vs LINQ Stored Procedure?

Aug 6, 2009

if there is that much of a performance gain in running a LINQ stored procedure versus a LINQ query?

View 1 Replies

Asp.net - Complex Linq Query - Add A .Where() Or .Any() Predicate To Reduce Query Complexity (in VB)?

Sep 14, 2010

I have to join two main tables, and I need to filter the results by elements in an ASP.NET web form. These filters are created on the fly so I have to use a lot of where extensions to filter the query. I want to execute the query with as optimized SQL as possible.

I am first doing a simple join between TW_Sites and TW_Investigators. Then there are two sub-tables that are involved. TW_InvestigatorToArea and TW_InvestigatorToDisease. While most of the where clauses are working fine, I have found a performance issue that won't be an issue right now, but will be an issue as the table gets bigger.

The arrays DiseaseCategories and DiseaseAreas would be the results of a CheckBoxList result.

Protected Sub LoadResults()
'Get Dictionary of Filters
Dim FilterDictionary As OrderedDictionary = Session.Item("InvestigatorFilterDictionary")
' Initialize LinqToSql

[code]....

View 2 Replies

Lamdba Expression, Use Assignment Operator Instead Of Equality?

Oct 27, 2010

I have a method that takes an System.Action, this is what I'm trying to feed it:Function() Me._existingImports = Me.GetImportedAds()

The thing is that it complains about the = sign since it thinks I'm trying to do a comparison, which I'm not. I want to assign the Me._existingImports the value of Me.GetImportedAds(), but VB.NET complains about DataTable not having a = operator.

How can I force it to use the assignment operator instead of the equality operator?

In C# this works perfectly fine: () => this.existingImports = this.GetImportedAds()

For now the solution will be to use a standalone method, but that's way more code than needed.

View 1 Replies

LINQ Query Using The Dynamic LINQ Library?

Mar 31, 2011

Forgive my ignorance on this.I have this LINQ Query:Dim ngBikersDataContext As New CarBikeWalkDataContext

bikersList = (From c In ngBikersDataContext.Reg_Bikers _
Order By c.L_Name _
Select New Bikers() With { _
.BikerID = c.BikerID, _
.F_Name = c.F_Name, _

[Code]...

with the error "Overload resolution failed because no accesible 'Select' accepts this number of arguments."
Over the "NEW" I get an error " ')'expected."

View 1 Replies

Ombine Two Linq Expressions Of A Custom Type (i.e. Expression(Of Func(Of MyClass, MyClass))

Nov 24, 2010

I have a list of properties and values that i'd like to use to dynamically build an Expression(Of Func(Of MyClass,MyClass))

I can run through the list and create each Expression by itself, but the only way I know how to combine them would be to use Expression.And or Expression.AndAlso, but that returns a BinaryExpression rather than my original Expression(Of Func(Of MyClass,MyClass)).

View 1 Replies

VS 2008 SQL Provider Named Pipes Provider Error 5 Invalid Parameter S Found

Aug 3, 2011

i have 2 computers - a Server and a Client pc which is running on local area network with MICROSOFT SQL SERVER 2008 R2 Developer kit at the main pc and Client computer will need to connect to SQL SERVER at main pc using connection string.Let me named server computer as 'MAGNA-PC' and the client pc as 'LAC-PC' and database name is 'db_referafriend' so the code for MAGNA-PC(server) connection string is:[code] i GOOGLE and YOUTUBE for almost 2 weeks before i post . I know that i need to configure the sql configuration manager and enable tcp/ip also add a new port at firewall to allow remote connection also add the sqlserver.exe and sqlbrowser in firewall and I have also chosen "Using both TCP/IP and named pipes" under Remote Connections in the SQL Server 2005 Surface Area Configuration. and all of this doesnt work!

View 10 Replies

Writing XML To Sql With Linq?

Nov 13, 2009

xml version="1.0" encoding="utf-8"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">

[code]...

View 6 Replies

"System.ArgumentException: An Item With The Same Key Has Already Been Added." When Trying To Order An In-memory LINQ Query By A LINQ Association?

Jan 27, 2011

We are doing a query against an in-memory collection of LINQ data objects. The wrinkle is that we are ordering by a column in a related table whose records have not necessarily been loaded yet (deferred loading:)

Dim oPkgProducts = _
From b In oBillPkg.BillProducts _
Where b.Successful.GetValueOrDefault(Common.X_INDETERMINATE) = _

[code]....

View 1 Replies

LINQ To SQL - Add In Row_Number To A LINQ To SQL Query?

Aug 31, 2011

How do I add ROW_NUMBER to a LINQ query or Entity? How can I convert this solution to VB.NET?

[Code]...

I'm having trouble porting that last line. I have been unable to locate a VB.NET example. I'm actually not looking for any paging functionality like the example provides, just good old-fashioned Row_Number(Order By X) row index.

View 1 Replies

Linq To XML: Writing Xsi Into An Element?

Feb 25, 2011

Just playing about with LinqToXml and I need to form a xelement as follows:

Dim xe As XElement = _
<Xml>
<ElementOne>
<SubElement></SubElement>
<SubElement></SubElement>

[Code]...

This creates an error here: xsi:type "XML namespace prefix 'xsi' is not defined"

Is it possible to write this in Linq to xml?

View 1 Replies

VS 2008 Linq Possible To Use Query In Another Query?

Apr 16, 2011

I was wandering is it possible to use a query within another query below is the code I am trying to use.

Public Function GetInventByComp(ByVal CompID As String) Using DC As New DataClassDataContext
'need to get company id's based off names? thats bad should be name from Id need to rethink this
Dim invent = (From C In DC.Inventors_Companies _
Where C.CompID = CompID _
Select C.InventorID).ToString

[Code]...

I was trying to us multiple values in a string like "1, 3, 5" but I can't seem to get that working either so I am trying to use just a single value now. Can anyone help me? "Yes I am new to this"

View 5 Replies

LINQ: Writing And Reading XML Settings?

Mar 8, 2012

i am having trouble reading my XML settings. I Create new entries like this

Private Sub Create()
Dim doc As New XDocument
If File.Exists("Settings.xml") Then
doc = XDocument.Load("Settings.xml")

[code]....

The XML file will have multiple <Network> Entrys. I cant figure out how to loop the file and get every <Server> entry. But then if i opened a form and gave the variable one of the server entries how could i get that <Network> based on the server entries child parameters.

View 10 Replies

Missing Last Row When Writing Query Results To Xls File?

Jul 22, 2011

I have a routine built to take query results and write them to an xls file. The problem is that I am only getting the column headers and 2 of the 3 rows of data. What am I doing wrong that the last row of data is not being written to the file?

[Code]...

View 2 Replies

Writing A Access Query In Visual Studio?

Dec 15, 2011

I have limited experience with Visual Studio and have a question about Querying an Access database. I have created a Visual Studio application that displays and modifies an access database. I have use datagridview and detailed view to insert data and view data in the Access database. I am now trying to figure out the best way to query the data in the database. I have tried right clicking a table in the database explorer and creating a new query. Everything works and I can view the data but I am unsure how to display this query result in datagridview. So my question is how do I view this result in datagrid view?

View 9 Replies

Writing A Query For A Column Named With Two Words?

Feb 15, 2010

I'm trying to make query in a table that has a column named "First Name"

dim info = from md in employees _where md!first name = "test"

How can I use the field "first name" in this query.

I've tried "first name" and ""first name"" but neither works.

View 2 Replies

Writing Query Data To A Text File?

Jan 30, 2010

We have a directory with a list of PDF files.Each file name has an Employee ID (eg 001213.pdf). What I need to do is loop through each file name, grab the employee id (001213) and pass it to Oracle query. The query wilbasically retrieve employee data (Firstname, lastname etc).

View 3 Replies

DB/Reporting :: Writing Colon - Syntax Error In String In Query Expression

Oct 12, 2008

Here is a code to insert data to DBaccess from textbox. When I write a colon(') in the textbox to add to DB it caused error and show me this Message "Syntax error in string in query expression '''')'

Code:
Dim conn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" _
& "Data Source =" & Application.StartupPath & "Store.mdb ")
Dim cmd As New OleDbCommand
cmd.Connection = conn
'Add text to DB
[Code] .....

View 8 Replies

.net - Should Use LINQ For This Query

Sep 4, 2009

I've been reading a fair bit about the performance of using LINQ rather than using a for each loop and from what I understand using a LINQ query would be a little bit slower but generally worth it for convenience and expressiveness. However I am a bit confused about how much slower it is if you were to use the results of the query in a for loop.

Let's say that I have a set called 'Locations' and a set of objects called 'Items'. Each 'item' can only belong to one 'location'. I want to link items that are under the same location to each other. If I were to do this using a normal 'For Each' loop it would be something like this:

For Each it as Item in Items
If it.Location.equals(Me.Location)
Me.LinkedItems.Add(it)
End If
Next

However if i was to use LINQ it would instead be this:

For Each it as Item in Items.Where(Function(i) i.Location.equals(Me.Location))
Me.LinkedItems.Add(it)
Next

is the second (LINQ) option going to loop once through the entire 'Items' set to complete the query, then loop through the results to add them to the list, resulting in essentially two loops, or will it do the one loop like the first (For Each) option?

View 2 Replies

Can Do A LINQ Query Of A LINQ Query?

Mar 24, 2012

Is it possible to do the following? [code] Basically I have one Load_Gridview function that is called on all postbacks, and rather than creating a bunch of different cases.I want the filters to stack.My actual code has more filters set up (4 or 5 of the).It all compiles ok but when I run and try to execute with active checked, or a department selected I get the following error. [code]

View 4 Replies

Linq Query In .net?

May 5, 2009

I have below XML file

<?
xml version="1.0" encoding="utf-8" ?><
PageFlow>
<
attributegroup name="Search"><
attributes>

[Code]...

View 2 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved