Query For Namespace Dynamically Using Linq To XML?

Mar 5, 2012

I have 290 Group Policy Backup xml files which I need to enumerate in separate folders.

With each Group Policy backup xml file, I need to query the Policy settings.

Anyone who's looked at a Group Policy xml backup file before would know they're chock-a-block full of Namespace declarations.

I want to know, using Linq to XML, as I query each xml file, how can I dynamically query the XML the Namespace and then append the Namespace into the Linq query for the child nodes/values?[code]...

View 3 Replies


ADVERTISEMENT

Linq Query Dynamically Add Where Condition?

Sep 3, 2010

I want to filter records dynamically on user choice. The user may choose to show the debit amount greater than credit or credit amount greater than debit. Accordingly I want to put a condition similar to either totDebit>totCredit orTotCredit>totDebit`

Dim query = _
From product In Bills.AsEnumerable() _
Group product By accode = product.Field(Of String)("ACCODE"), _

[Code]....

View 2 Replies

Dynamically Building LINQ Query Using OR Operator In VB

May 22, 2009

I need to build a dynamic linq query with or operators. I have seen PredicateBuilder but that is in C# and my project is in VB. Basically I need to build a WHERE clause similar to this:

Where((this = 1 AND that = 2) OR (this = 1 AND that = 4) OR (this = 2 AND that = 4))

but the problem is the number will have to be determined dynamically at runtime, and added using a loop, like

for each item in myItems
query = query.OR (this = item.a AND this = item.b)
next

View 2 Replies

VS 2010 Dynamically Building LINQ Query To Search Objects

Mar 24, 2011

I am creating a mediaplayer / playlist creator tool that basically imports MP3 songs into playlists (grids). I'm looking to add search functionality where the user can search all open playlists (or a subset of the open playlists). A Playlist is basically a collection of AudioFiles, where an AudioFile is a class that holds the filename of the MP3 file and then exposes the tags (Title, Artist, Album, etc) in public properties.

The idea is that the user can search for a certain expression (for example "the"), and that he can then choose whether to search in the title, in the title and artist, in the title or artist, in the title, artist and/or album, etc. However, I'm having a hard time implementing this and also having it kind of dynamic.

At the moment I am simply gathering all the AudioFiles from the open playlists (or from the subset of playlists the user chooses) and then running a simple LINQ query to find those AudioFiles where the Title contains the search text. Then I display the resulting AudioFiles in a new playlist window:

[Code]....

In case the AND / OR distinguishing is too hard, I would be happy to start with just letting it default to 'OR', so that the user can check Title and Album for example. If he would then search for 'a' then all songs that contain 'a' in their title as well as all songs that contain 'a' in their album should be returned. I guess that makes it easier, but I still wouldn't know how to dynamically create the LINQ query.

View 2 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

Dynamically Set Local XML Namespace?

Sep 1, 2010

I have several xml namespaces that expose the same schema.

I want to use a function that dynamically accepts a namespace and applies the attributes or the properties according to the specified namespace:

Public Sub ProcessElement(element As XElement, [namespace] As XNamespace)
element.<[namespace]:Property>.Remove()
End Sub

I actually want to set the namespace resultion withing this function to the given argument.

Look at this article, he does exactly what I want, but I am sure that in VB.NET XML Literals there is a much nicer way than doing it the hardcoded way.

I know I can simply do it like this:

element.Elements([namespace] + "Property").Remove()

But I was wondering if there is a way to include namespaces in VB.NET amazing .<>, .@, ...<> language shortcuts.

View 1 Replies

System.Xml.Linq Namespace?

Jan 13, 2011

I have been given the task of calling a web service which returns an xml data feed which I am doing like so;

For Each r As DataRow in SomeDataTable
Dim msFeed As String = string.format("http://some-feed.com?param={0}", r!SOME_VAL)
Dim x

[code].....

View 4 Replies

Getting The Namespace System.xml.linq To Be Recognized?

Oct 26, 2008

I am using VS 2008 but am having problems getting the namespace system.xml.linq to be recognized. I am attempting to add the reference but I don't seem to be be allow to select it.System.XML.Linq is grayed out in the AddReference menu. What must I do to add this reference to my project?

View 3 Replies

Linq To Xml Syntax For Documents With Xml Namespace?

Aug 6, 2010

I'm trying to grasp the linq to xml 'inline query syntax' features of VB.Net First I tried with this simple xml file:

<?xml version="1.0" encoding="utf-8" ?>
<Root>
<Child Name="somename">

[code]....

This xml, when loaded in an XDocument, can be loaded and queried as follows:

Dim xdoc = XDocument.Load("sample.xml")
Console.WriteLine(xml.Root.<Child>.@Name)

Then I change the <Root> element in the sample xml file to:

<Root xmlns="http://SomeNamespace">

Now I can't seem to use the convenient 'Axis Properties' syntax anymore... I can only get it to work with the explicit XElement syntax:

Dim ns As XNamespace = "http://SomeNamespace"
' works, but I would like to use the same syntax as above...
Console.WriteLine(xdoc.Descendants(ns + "Child").First().Attribute("Name").Value)

View 1 Replies

Read An XML Node In Namespace Using Linq

Feb 28, 2012

How do I work out what the namespace declaration is for the Extension node?I want to return all of the child nodes under: GPO->User->ExtensionData->Extension..[code]I get the following error: Sequence contains no elements..Also, the XML sample I have provided is only a small snippet, the ExtensionData->Extension nodes can be nested in different areas, so I was hoping to find the way of specifying the full path.

View 2 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

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

LINQ To XML: Suppressing Redundant Namespace Attribute In Child Nodes

Feb 25, 2010

If a node belongs to a namespace, it's children by default belong to the same namespace. So there's no need to provide an xmlns attribute on each child, which is good. However. If I create two nodes like this:

[Code]...

View 1 Replies

Using LINQ To XML With Global Namespace - Xmlns Is Added To Each Non-data Element?

Jan 14, 2010

I have to create an xml doc for a vendor who specifically states they must have their xml as follows:

<?xml version="1.0" encoding="utf-16" standalone="yes"?>
<WMWROOT xmlns="http://www.blahblah.com/BLAH/Interface">
<WMWDATA>[code].......

I cannot find a way to get LINQ to spit out xml the way they want. Question is, can LINQ do it or do I need to resort to hardcoding the xml the old way before LINQ to XML?

View 5 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

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

Setup Linq To SQL Dynamically?

Jan 29, 2010

In my application I use Linq to SQL to communicate with my SQL database.To setup a connection I added a Linq to SQL class, selected a database and choosen a SQL table.After this I use the following code for showing SQL data:Using aw As New LinqtoSQLDataContext

Dim Data = From c In aw.TestDatabase_TestTable _
Select c.No, c.Description
DataGridView1.DataSource = Data
End Using

Now the link to the SQL database is hardcoded and the databasename must be used in every Linq-statement.Is it possible to make the link to the SQL database dynamic so I can switch easyily between a test and production database?Can the tablename inside the Linq statements be dynamic too?

View 6 Replies

Pass Stored Procedure Name Dynamically To Linq-to-SQL?

Jul 11, 2011

How can I pass stored procedure name dynamically to Linq-to-SQL, vb.net and get the result into a datatable.

View 2 Replies

Dynamically Select Table At Runtime With Dynamic LINQ?

Feb 17, 2011

I'm developing an application to allow engineers to conduct simple single table/view queries against our databases by selecting Database, Table, Fields.

I get how to use the Dynamic LINQ Library Sample to provide for dynamically selecting the Select, Where and Order by Clauses at runtime but I'm at an impass on how to allot for table choice.

Is there a way to provide for dynamically selecting the "from" table at run time

EDIT

So Both of the answers seem to be saying the same general Idea. I'm going to try to convert the C# into VB and get it to work.

The first answer converts to

NotInheritable Class DataContextExtensions
Private Sub New()
End Sub

[Code].....

View 2 Replies

Sql - Dynamically Varied Number Of Conditions In The 'where' Statement Using LINQ?

Feb 3, 2010

I'm working on my first project using LINQ (in mvc), so there is probably something very simple that I missed. However, a day of searching and experimenting has not turned up anything that works, hence the post.

I'm trying to write a LINQ query (Linq to SQL) that will contain a multiple number of conditions in the where statement separated by an OR or an AND. We don't know how many conditions are going to be in the query until runtime. This is for a search filter control, where the user can select multiple criteria to filter by.

select * from table
where table.col = 1
OR table.col = 2
OR table.col = 7
'number of other conditions

Before I would just construct the SQL query as a string while looping over all conditions. However, it seems like there should be a nice way of doing this in LINQ. I have tried looking using expression trees, but they seem a bit over my head for the moment. Another idea was to execute a lambda function inside the where statement, like so:

For Each value In values matchingRows = matchingRows.Where(Function(row) row.col = value)However, this only works for AND conditions. How do I do ORs?

View 3 Replies

.net - The System.Linq.Dynamic Namespace - Visual Studio Does Not Recognize In The Project Files The System.XXX References

Aug 11, 2011

I would use the System.Linq.Dynamic. I added the specified Dynamic.vb file, that starts like this:

[Code]...

to my (VB.NET)solution. Now Visual Studio does not recognize anymore in the project files the System.XXX references, proposing me to change them to Global.System.XXX

View 1 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

Put A Sum() In Linq Query?

Apr 18, 2012

I am looking to sum the "Status" field.

Dim _detailRecords As New DataTable
_detailRecords.Columns.Add("y")
_detailRecords.Columns.Add("z")

[Code]....

I'm also wanting to keep this as an IEnumerable of DataRow because I will be creating a datatable from it with

Dim yyyyy As DataTable = query8.CopyToDataTable

View 1 Replies

Query With Linq To Xm?

Aug 13, 2010

I am Fairly new to Linq and I am trying to write a simple query to return the error messages within my xml file.

<?xml version="1.0" encoding="utf-8"?>
<Error xmlns="urn:xxxxx">
The following errors were detected:

[code].....

View 1 Replies

Why The Sql Query Is Different On That Linq Query When Run On C# And On .net

Aug 26, 2009

if I run this under c#

from p in Addresses where p.Address2 == null select p.AddressID

it generate this query

SELECT [t0].[AddressID]
FROM [dbo].[Address] AS [t0]
WHERE [t0].[Address2] IS NULL

if I run this under vb.net

from p in Addresses where p.Address2 = nothing select p.AddressID

it generate this query

SELECT [t0].[AddressID]
FROM [dbo].[Address] AS [t0]
WHERE [t0].[Address2] = ''

p.Address2 is a varchar field that accept null value

why vb.net is "wrong" ?

View 1 Replies







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