Creating Objects From Child Elements Using LINQ To XML
Feb 1, 2011
Is there any way to use a LINQ to XML to query an XML document like the one below to create new (anonymous or strongly typed) objects from the child elements of a descendant? Here is my XML document:
[Code]...
View 2 Replies
ADVERTISEMENT
Aug 17, 2009
I'm having trouble adding child elements to the below
<securities>
<security id="040104JC6">
[code]....
View 2 Replies
Mar 8, 2010
I have got an xml document which looks something like this.
<Root>
<Info>
</Info>
<Info>
[Code]...
How can i write a linqToXML query so that it returns me an IEnumerable containing each child element, in this case all five child elements of , so that i could iterate over them. The order of child elements is not definite, neither is number of times the may appear.
View 1 Replies
Nov 20, 2009
I am creating a tool that interfaces with an API for a CD/DVD burner. I have created several custom classes that will hold the information for the disk sets (which consist of a data path and a label file among other information. The DiskSet class has a list of Include objects. My proposed XML output would be something similar to the following:
<DiskSets>
<DiskSet>
<Name>MySet 1</Name>
[code].....
I am attempting to traverse the Includes collection (I have tried List and Binding List as I am also using this in a pair of datagridview controls) and it keeps returning Expression of type 'Object is not queryable. Make sure you are not missing an assembly reference and/or namespace import for the LINQ provider." How can I use LINQ to pull a list of the Include objects under each DiskSet object for transformation into XML? I am hoping to keep this restricted to this one block of code if possible.
View 7 Replies
Oct 13, 2011
Basically I have the follwing:Dim ctx As New AdminCoreEntities Dim roles = (From r In ctx.Roles where r.Name.StartsWith("cust") Select r) 'list of System .Linq.IQueryable(Of AdminCoreModel.Role)
[code]...
The error i get when i run this is: Unable to cast object of type System.Data.Objects.ObjectQuery`1[AdminCoreModel.Role] to type AdminCoreModel.Role
Basically I have a many to many situation and I try to get all the Quicklinks objects queried by their roles and not quite sure why EF will cast to a single AdminCoreModel.Role when i.Roles is a collections of objects.
View 1 Replies
Dec 26, 2010
I have a Clients master object and then a number of child objects whose exact number is not known in advance such as Client-Contacts, Client-Payments etc, all of which have a one-to-many relationship with the Client master object.How do I define classes for such a scenario? Do I for instance create the master Clients class and can then I create an array of class somehow for child objects?
View 2 Replies
Oct 25, 2011
I am in the process of learning LINQ to Objects. I am querying an array of reference elements using LINQ. In the code below, which I have marked with asteriks and PROBLEM, I am having difficulty returning any values for and I suspect its because of the multiple Select arguments.
'Program name:Querying an Array of Invoice Objects
'Created/revised:
'Project description:To demonstrate the use of LINQ to query objects
[Code].....
View 4 Replies
Jan 3, 2012
I have a nested class, let's call it class1 and it has class2 inside it; VB.Net eg:[code]
1) How can I define X number of Class2 objects[let's call it: Node(x) array]** with NEW() subroutine called?' this raises error: dim cls2(n) as new class2 end sub.
2) How can I return actual number of Node() array? [code]Outside my class in main project I define cls1 object:[code]Now an array of class2 is created inside cls1.
3) Now,How can I access All of them[node(x) array which is created inside cls1] with all properties and methods available?
I remember I wrote a ProcessManager class with this functionality in .net 2003, nearly 4 years age, I don't have the code now.
View 1 Replies
Aug 31, 2011
I don't know if this is doable, maybe with Linq, but I have a List(Of MyType):
Public Class MyType
Property key As Char
Property description As String
End Class
And I want to create a Dictionary(Of Char, MyType) using the key field as the dictionary keys and the values in the List as the dictionary values, with something like:
New Dictionary(Of Char, MyType)(??)
Even if this is doable, internally it will loop through all the List items, I guess?
View 3 Replies
Feb 3, 2010
Basically, I am trying to write a LINQ to Objects statement where the relationship is a grandparent, parent, child relationship. (You could also call it a Master Detail relationship.)
Dim coverages As New List(Of Coverage)
Dim coverage As Coverage
For Each rl In oClaimsPolicy.RiskLocations
[code].....
View 1 Replies
May 1, 2009
long story short, I have created a ListView type control, using UserControls for the parent control and the ListViewItems. Most the of the control is written and works fine, right up to the point where I tried to replicate the 'Control.SelectedItems(0).Index' property and the 'SelectedIndexChanged' event.
Each child object knows its index value, and could pass this value via the SelectedIndexChanged event (assuming this is how it works in a normal ListView control -- user clicks on an item, and that item fires an event updating the selected index value in the parent object).
How does the child object raise an event in the parent object? I have a feeling this could be done with Delegates, but I'm still learning about their usage.
View 1 Replies
May 21, 2012
Dim obj_DataTable As New System.Data.DataTable("Category")
Dim obj_DataSet As New DataSet()
'Declaring the array of DataColum to hold the Primary Key Columns
[code].....
View 1 Replies
Jul 6, 2011
I have to get all the Entity Source,Entity Target,Property Source and Property Target values in list respectively.[code]...
View 1 Replies
Jun 21, 2011
I ham developing a Silverlight RIA solution that needs to return a hierarchical model from the server which is declared as below.
Imports System.ComponentModel.DataAnnotations
Imports System.Collections.Generic
Imports System.Runtime.Serialization
[code].....
View 1 Replies
Aug 30, 2011
I have a grid in which I have created and added elements from the code behind.
Dim staffImgLeft As New Controls.Image()
staffImgLeft.Name = "StaffImgLeft"
mainGrid.Children.Add(staffImgLeft)
When I am attempt to remove the child elements from the grid they are not being removed.
mainGrid.Children.Remove(mainGrid.FindName("StaffImgLeft"))
There are no errors when the code runs. Can anyone advise why my code isnt working?
View 2 Replies
Mar 26, 2010
I have the following piece of XML:
<xml>
<ObsCont xCampo="field1">
<xTexto>example1</xTexto>
[Code]....
How do I (using linq) get for example what is inside the xTexto tag that has as parent the ObsCont with the xCampo attribute "field2" ?
View 3 Replies
Nov 16, 2011
I have the following tables
Public Class Tag
<Key()> _
Public Property TagID As Integer
[Code].....
I implemented the repository pattern.
Now i have a list of Tags which contain the right TagReferences, but the tags may not be deleted, it's the TagReferences.
Variabels = ReferenceValue,ReferenceID
IEnumerable(Of Tag) = TagRepository.GetMany(Function(el) el.Reference = ReferenceValue And el.TagReferences.Any(Function(bl) bl.ReferencedID.Equals(ReferenceID)))
How can i remove all the TagReferences which contain the ReferenceID in one line?
View 1 Replies
Jul 9, 2010
I have a table (Projects) which is linked to projectVersions on projectID..projectVersions contains several columns on which I'd like to filter a returned project (and associated projectVersions) list. For example there is a "capacity" column and a "country" column. I am doing a filtered list of projects on one page and I'd like to include all projects where any one of the associated projectVersions has a capacity of 750ml and a country of "France" for example.It may be that a particular parameter is not set and so I pass a zero to indicate not to filter on that.I guess this needs some kind of subquery as when I try and do something like this: [code] it doesn't work as the "xxx" bit, being one-to-many, expects me to specify an item to get at the entities within and yet I want to query where ANY of the associated versions match one of the criteria.
View 1 Replies
Nov 29, 2011
how to search XML trees with LINQ using VB.net. I've found some very helpful posts for C#, but none for VB.net?How would I use LINQ to XML to get the value from example XML Getting a set of elements using linq How to get elements value with Linq To XML I want to get the inputlocation for the process where name = "MyProcess1" Based on the example links above, I have been trying code like this:
Dim inputLocation As String = xdocument.Descendants("Configurations").Descendants("process").First(Function(c) c.Element("name").Value = "MyProcess1").Element("inputLocation").Value
But the code is not returning any values. here is the xml
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Configurations>
<process>
[code]....
View 1 Replies
Mar 16, 2012
I would like to get the first N groups elements with Linq of a ObservableCollection, an example trying to get the first 2 groups:
Data example:
GROUP1 item1
GROUP1 item2
GROUP1 item3
GROUP2 item1
[code]....
View 5 Replies
May 25, 2011
I have this XML
<?xml version="1.0" encoding="utf-8"?>
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="[URL]" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="[URL]" />
<xsd:element name="root" msdata:IsDataSet="true">
[Code] .....
And I also have this method, where I take two files and take some values from them, and then I merge all the values into an object in the second query:
Public Shared Function RetrieveTranslation(ByVal filefrom As String, ByVal fileto As String) As List(Of clsTranslation)
Dim valuefrom = (From l In XElement.Load(fileto).Elements("data") Select l.Element("value").Value).FirstOrDefault
[Code] .....
So, the problem is that when I run the code, there is an "Sequence contains no elements" error in the first query(valuefrom). I debugged and it says that there is nothing in the query, but I don't understand why? I'm curious to know if it is well done to do something like I did, create an object from two queries, putting the first value in the second query.
View 1 Replies
Jan 27, 2010
some of the xelements within the query were calling for tags that didn't exist in the original xml, heres a simple example of what i mean.
element = _
<xml>
<object>
<string>someString</string>
[code]....
So how do i change the querry so that it wont produce a null error if the tags asked for are not present.
View 7 Replies
Mar 30, 2012
I'm really struggling with this. I have two XML files. The first one has items, and then sub elements for properties:
[Code]...
View 3 Replies
Oct 20, 2009
I've become undone when trying to convert xml linq query result to a datagridview (see code below), needing some pointers,.
Dim doc As XDocument
doc = XDocument.Load("C: empxmltest.xml")
Dim query = From c In doc.<quotefile>.<quote> _
[code].....
View 3 Replies
Mar 9, 2011
I have the following XML which I load via XDocument.Load(uri) or XElement.Load(uri). I am having trouble getting a collection of <asset> elements via LINQ.
Here is a snippet of the XML I'm trying to query:
<assetCollection xmlns="tag:aisle7.net,2009:/api/1.0">
<title>All Assets</title>
<description>Collection containing all assets in the system</description>
<resourcePath>/us/assets/~all</resourcePath>
[Code] .....
View 2 Replies
Mar 22, 2009
I'm working on a .NET application (VB 2008) that gets all of its data from a web-based Django application.I'm using Linq-to-XML and Linq-to-objects in the app.One API call is giving me XML data in the following format that I am loading into an XDocument.
[Code]...
View 1 Replies
Feb 8, 2010
I've created managed code to programmatically provision websites on Windows 2008 servers from a Vista 64-bit workstation.The provisioning covers creating DNS entries, creating a file structure and a the IIS7 site (using Microsoft.Web.Administration aka MWA).I've had to do some DCOM configuration to get it to work through a firewall and it all works on the test server provided I'm in the same domain.I then cloned the Windows Server 2008 Virtual Machine (VM) that the provisioning does work on and then changed the clone's domain to the child domain in the forest where the production servers are sitting.The provisioning user credentials are synchronised on the parent and child domains.So the only change is moving domains and there is an automatically configured trust relationship between the domains.
Provisioning the file system still works on the server on the child domain, but managing DNS and IIS7 now have access issues.I've tried impersonating the Administrator on the child domain (and the thread identity is showing that works) and also had a go with CoInitializeSecurity (though I'm not sure that is appropriate for Win2008 and Vista)to no avail.What I really want to avoid is the need to have to store credentials separately on the workstation - it brings an unwelcome maintenance overhead and the possibility that if the provisioning user's password is changed, then the provisioning will unexpectedly fail on the production servers.Ideally once the provisioning user has logged onto the Vista Workstation, I'd like their credentials to pass through to the servers on the child domains (there are separate DNS and web servers) allowing them to manipulate whatever services (DNS, IIS7, file system) that are necessary.The solutions would seem to be something programmatic (whatever replaced CoInitializeSecurity?) or a Group Policy setting on the child domain may need altering to allow access.However being a humble software developer working out which of the myriad settings (one of the User Rights Assignments perhaps?) is outside my sphere of knowledge.The third alternative is to use Windows Communication Foundation (WCF) but I haven't done much with this yet and what I have indicates that this technology has its own security issues to accommodate.
View 5 Replies
Nov 5, 2010
I am developing a new class which is a control that inherits from the "Panel" class. In this new class, I have three objects that are generated every time I create a new instance of the class. For simplicity, I will call this class "garage" and the three objects "BMW," "Lexus," and "Acura." So each new garage has three types of cars.
how can I share a variable from the Parent class with all of it's child objects? i.e. The garage has an array variable called "tires" which all three cars use. Rather than create each car object with the tires parameter, I would just like to keep the tires parameter in the parent class so that all my child objects can use it. I know that normally the parent class should provide the child class with all information when creating the child but it would seem redundant to pass the entire tires array each time since all three cars use the same tires and the tires object never change.
View 4 Replies
Feb 23, 2009
I coded a class that scans an object and maps data from a data table into each one of the corresponding properties, it works very well, however I am not able to set the property of one of the child (coplex objects)
Public Class CntrConfHdr
Private m_CntrConfHdrID As Double
Private m_HeaderCode As String
[Code]...
I want to set the value for the child object TypeCurrency.TypeCurrencyID thus I set the value of the variable sTargetPropertyName to TypeCurrency.TypeCurrencyID but the application willnot work stating that the property can not be found.
View 1 Replies
Oct 15, 2009
What is the best way to pass objects between threads? I would like to create a new thread that creates a new object : Dim myobject as newobject = new newoject Then in my main thread, I would like to use myobject. Ideally I would like to just assign to a global variable but I don't think that is possible. I think I may have to use some form of delegate function (but I think the child thread would need to complete to use a callback). The new thread will not actually end before I need the object reference in the main thread. How should I go about this?
View 2 Replies