Get Value Of A Known Attriubute In LINQ?
Nov 28, 2009
I'm writing a WPF app that will display severe weather alerts for an inputted zipcode. I'm using Weather Underground's AlertsXML API to get appropriate information. Where I'm getting hung up is getting the value of the count attribute of the alert element (as in the 2 from <alert count="2">) so that I can perform some logic with it. I've been looking over some of the documentation on it (such as this ), as well as a completely unrelated implementation of LINQ in another project of mine. I can't get it to work.
Obviously the XML is in a static layout, so what I'm asking is how I would go about getting the value of a specific attribute within a specific element in an XDocument.[code]...
View 2 Replies
ADVERTISEMENT
Feb 25, 2011
I have a asp:DropDownList element that I need to reference in my code behind but I need it to have a very specific name that has special characters so I cannot use that as the id.
View 1 Replies
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
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
Apr 20, 2011
I have a listbox on my xaml form that I bound to a List(Of MyType) property. I populated this list like so:
Dim fields As List(Of CheckableFields) = New List(Of CheckableFields)
Using context As ITIPEntities = New ITIPEntities()
Try[code]....
Now I'm at the point where the user selects the fields they want included in a report and I need to iterate over the required fields. This is my linq query:
For Each checkedField In _requiredFields
If checkedField.IsChecked Then
If checkedField.FieldData IsNot Nothing AndAlso checkedField.FieldData.Trim IsNot String.Empty Then[code].....
View 1 Replies
Sep 10, 2009
Example-I have a person class
Public Class Person
Private _fname As String
Public Property Fname() As String
[Code]...
View 2 Replies
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
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
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
Jun 27, 2012
How can I convert this code LINQ to SQL in C # LINQ to SQL in Vb.net
[Code]...
View 2 Replies
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
Oct 21, 2009
How can I convert an object of type System.Data.Linq.DataQuery to System.Linq.IQueryable?I'm working with Visual Basic/Silverlight, and the source code of my query is as follows:
Public Function Get_Cli_Pag() As IQueryable(Of V_Cliente_Pagare)
Dim Qry = From P In Me.Context.Pagares Join C In Me.Context.Codigos On C.Codigo
[code]....
View 1 Replies
Apr 20, 2010
I just upgraded a project from VB 2008 to VB 2010. Before, the project did not use LINQ. I have started implementing it. So, I have updated the target framework from 2.0 to 3.5, and added a reference to System.Core, and imported the namespace System.LINQ to the entire project and also imported System.Data.LINQ into the form I'm working with (because it was not available in the list for Imported Namespaces in the references tab).
It's not throwing any errors now, but my IntelliSense is not working for LINQ stuff.
For example... I write this:
[CODE]....................
Then, if I type S. on the next line, the IntelliSense doesn't grab what it should for S (Only get Equals, GetHashCode, GetType, ReferenceEquals, and ToString, instead of the options I should get like Count, First, FirstOrDefault, etc...). If I Type S.First. then its the same thing, no IntelliSense that lists the available fields for S, just the standard options (Equals, GetHashCode, GetType, ReferenceEquals, and ToString). I should be seeing my column names in my table when I type S.FirstOrDefault.
So any ideas what is going on? When I type the code, for example, MessageBox.Show(S.FirstOrDefault.FirstName), it works perfectly. But it doesn't change the casing of the text (so it would read s.firstordefault.firstname) and no intellisense while doing it. But no errors. BTW - Everything works perfectly when creating a NEW VS 2010 application, it's just my projects upgraded from Visual Basic 2008 that have this issue.
View 2 Replies
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
Feb 22, 2012
I recently switched from VB to C# and have, for the most part, been able to make the transition without too much trouble. Currently I am working on converting a VB.Net program into C# and am having trouble with a couple of code blocks that include Linq.
This is one of the VB.Net lines of code that I am having trouble with:
I have tried to do the same thing in C# like this:
I am getting a compile error on the dt, which says Could not find an implementation of the query pattern for source type 'System.Data.DataTable'.'GroupBy' not found. VS also has issues with the whole into Emailers = group;
I have tried to get this right using examples from my search but have not been able to get it right.
View 2 Replies
Jul 28, 2009
suppose I wanted to make a function that returned a list of people based on 2 criteria ... FirstName = 'Ed' Or LastName = 'Smith'.The key here being the OR. If I do something like the following:
dim qry = From p in db.Person select p.FirstName, p.LastName
qry = qry.Where(Function(p) p.FirstName = 'Ed')
qry = qry.Where(Function(p) p.LastName = 'Smith')
[code].....
View 7 Replies
Oct 19, 2011
convert it to C# equivalent
Dim dtData As DataTable = Session("Data")
Dim aFilters = From oRow In dtData _
Where oRow(i_oColumn.BaseColumnName) IsNot DBNull.Value _
[Code].....
View 1 Replies
Jul 6, 2011
My friend told me some linq and mysql.
I not know what is LINQ.
is dll?
is addins for visual studio?
where do i download?
View 2 Replies
Sep 22, 2010
I am having some difficulties with sending XML data to SQL using Linq.I have been following the tutorial link below, however my XML data doesn't contain a root value like <order number> to go through each of the XML data. There is no unique reference as part of the <quote> information.[URL]..
Is there a way I can submit the changes to SQL using the <reference> field as the unique field even though it is not related to <quote>?
[Code]...
View 9 Replies
Apr 12, 2011
I'm in the process of teaching myself C# by converting an existing project and am stuck converting the following vb linq code:
Dim outStuff = From tt In (From t In Products.SelectMany(Function(p) If(p.tags IsNot Nothing, p.tags, New ObservableCollection(Of TagModel)))
Group By tagName = t.name,
v = (Aggregate p In Products Where If(p.tags IsNot Nothing, p.tags.Contains(t), Nothing) Into Sum(p.views)),
nl = (Aggregate p In Products Where If(p.tags IsNot Nothing, p.tags.Contains(t), Nothing) Into Sum(p.num_likes))
[Code]...
var x = Products.SelectMany(p => (p.tags != null) ? p.tags : new ObservableCollection<TagModel>());
var tags = from t in x group t by t.name into g select new { tagname=g.First().name};
View 2 Replies
Feb 5, 2010
I'm having a heck of a time with transforming a simple SQL Query into a LINQ query(using vb btw)
Here is my SQL:
SELECT USRDEFND5
FROM int_gp_employee
GROUP BY USRDEFND5
[Code]...
I've tried a number of different variations of the LINQ. My current statement is:
From b In xmlFile...<row> Group b...<usrdefnd5> By b...<usrdefnd5> INTO group when I foreach through the resulting collection, EVERY line (17000) shows up.
View 2 Replies
May 17, 2011
I am using LINQ to XML to take some data from resources , and here I have a function, where I take some values and then I create a new object (Type Translation), so when I call the function I get a Translation object. By now I have this code:
Public Shared Function RetrieveTranslation(ByVal file As String) As List(Of clsTranslation)
Dim valuetrans = From vl In XElement.Load(file).Elements("data") Select (New clsTranslation With {.Filename = file, .Value = vl.Element("value").Value, .TranslationId = vl.Attribute("name").Value})
Return valuetrans
End Function
The problem is that with this code I got this error:
Unable to cast object of type 'WhereSelectEnumerableIterator2[System.Xml.Linq.XElement,clsTranslation]' to type 'System.Collections.Generic.List1[clsTranslation]'.
View 1 Replies
Feb 24, 2011
I have an XML file, with a rather large structure. I'm pulling several entities out of it throughout several systems, and its dynamically updated once a day. I'm using a Linq Query that is exhibiting odd behavior, its only returning if the first entry in the site tag matches the search-pattern. If its number 2 or 3, it fails to return anything. Why would this behave that way?
The following function written in VB handles pulling the data
Public Function xmlSchoolListBySite() As IEnumerable
Dim doc As XDocument = loadXML()
Dim loadedPrograms As IEnumerable(Of XElement) = From c In doc.Descendants("Organization") _
Where c.Descendants("site").Value = MySite.Site.s_Url _ 'contains Result.RawURL.tostring() formatted
Select c.Element("Title")
[Code]...
View 1 Replies
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
Jun 24, 2009
Why does VB have more LINQ keywords than C#?
View 4 Replies
Apr 15, 2011
I'm trying to join two datatables of same keyfields.
table1
ID Class
---- -----
1 10
2 9
[code]....
Result
ID Class1 Class2
1 10 8
2 9 7
View 2 Replies
Aug 17, 2009
I'm having trouble getting a Linq to Sql query to work. Basically, I want the sum of a column in a table for only rows matching a certain condition. A simplified version is this:
Orders = order that contains products
OrderProducts = relational table containing products that are in an order
Products = table containing information about products
I can get the total sum of the qty of products like this:
Dim totalQty = requests.Sum(Function(p) p.OrderProducts.Sum(Function(q) CType(q.ProductQty, Nullable(Of Integer))))
(Requests is a IQueryable of Orders)But I also need to get the sum of qty where the actual product meets a certain condition. Something like...
Dim totalQty = requests.Sum(Function(p) p.OrderProducts.Sum(Function(q) CType(q.ProductQty, Nullable(Of Integer))))... WHERE p.OrderProducts.Product.ProductAttribute = true
How would I go about getting that query with the additional where clause to only get the sum of the qtys where the productAttribute = true ?
View 1 Replies
Aug 9, 2010
I have the following LINQ statement, which performs a simple linq query and assigns the resulting values labels on an asp.net web form:
Dim db As New MeetingManagerDataContext
Dim q = From s In db.vwRoomAvailabilities _
Where s.MeetingID = lblMeetingID.Text _
[code]....
Originally, there was going to be only a single row result and you can see I'm using FirstOrDefault() to grab that single value which works great. But the design has changed, and multiple rows can now be returned by the query. I need to now Group By the MeetingID above, and SUM each of the selected columns (i.e. s.AllRequestedDoubles).
View 1 Replies
Nov 15, 2010
I'm having a bit of issue converting the following t-sql statement to Linq (using 4.0 entity framework)
[Code]...
View 1 Replies
May 18, 2010
I have a dataset that is populated via a SQL Stored Procedure, the format of which is below: Country | Brand | Variant | 2004 | 2005 | 2006 | 2007 | 2008 The number of rows varies between 50 and several thousand. What I'm trying to do is use Linq to interrogate the dataset (there will be several Linq queries based on user options), but a simple example would be to SUM the year columns based on Brand. I have the following that I believe creates a template for me to work with: But from here on I'm absolutely stuck!
[Code]...
View 1 Replies