Working With Types With Linq In VB, C# - Dim LoTupleSetDifference = LoTupleKeys.Except(loTupleExistingKeys)

May 6, 2009

Say I create two sets of tuples like so:

Dim losSPResults As List(Of spGetDataResults) = m_dcDataClasses.spGetData.ToList
Dim loTupleKeys = From t In losSPResults Select t.key1, t.key2

[CODE].....................

Now I want to perform set operations on these two lists like so:

Dim loTupleSetDifference = loTupleKeys.Except(loTupleExistingKeys)

Obviously, Linq can't perform a comparator on sets if it doesn't know the sets have uniform definitions, so it will give me this build error:

Option Strict On disallows implicit
conversions from
'System.Collections.Generic.IEnumerable(Of
< anonymous type>)' to
'System.Collections.Generic.IEnumerable(Of
< anonymous type>)'.

How do I work with the declaration of these sets to make them mesh?

Still getting the same compile error:

'*** If we have initialized the list of tools, check to make sure it's up to date Dim loTupleDatabaseTools = From tt In lottTorqueTools _Select StationIndex = tt.station_index, SlotNumber = tt.slot_number

[CODE]...............

Error is here:

Dim loTupleSetDifference = loTupleDatabaseTools.Except(loTupleToolObjects)

Error 5Option Strict On disallows
implicit conversions from

[CODE]........................

View 1 Replies


ADVERTISEMENT

C# - Linq Group By With Anonymous Types Not Working As Expected?

Jul 14, 2011

I was toying around with some of the linq samples that come with LINQPad. In the "C# 3.0 in a Nutshell" folder, under Chater 9 - Grouping, there is a sample query called "Grouping by Multiple Keys". It contains the following query:

from n in new[] { "Tom", "Dick", "Harry", "Mary", "Jay" }.AsQueryable()
group n by new
{

[Code].....

View 1 Replies

Using Linq And Anonymous Types?

Jun 29, 2009

I have a problem using linq and anonymous types in an asp.net vb.net application.When I write the code above, I have 2 errors :

- "declarations of variable with Option Strinct On requires an As clause"

- "the name 'item' is not declared"

Public Sub MyFunc(ByVal xe As System.Xml.Linq.XElement)
Dim lstitems = From it In xe.Elements Select txt = it.@Text, value = it.@Value
For Each item In lstitems
Dim s As String = item.txt
Next
End Sub

Does it mean that is not possible to use Option Strict On and Option Explicit On ?Or I make a syntax error ?Or is it just a bad configuration of my application ?

View 2 Replies

.net - How To Pass Linq To SQL Types To A Function

Aug 27, 2011

The code below is used in a Linq to SQL solution, and is in the Load event of a form. It works fine to display an ordered list of people's names, and set the value member to that person's ID. However, I'm going to be using these 'people' comboboxes a lot, so I'd like to put a sub into my Utility code there is only one line in the form's Load event.

I want to call something like: Call ComboboBoxPeople(cbo, tblTurnbackMain, ReportedByID)

The sub would begin like: Public Sub ComboboxPeople(cbo as Combobox, tbl as 'sometype', fld as 'someothertype')

What can I use as the parameter types for tbl and fld?

[Code]...

View 1 Replies

Using Reflection On Anonymous Types: LINQ To SQL

Mar 19, 2010

I would like to use reflection on an anonymous type resulting from a LINQ to SQL query. I know that reflection on anonymous types works in general. The following code successfully generates a propertyinfo array with two elements:

Dim MyObject = New With {.Col1 = 1, .Col2 = "Test"}
Dim t As Type = MyObject.GetType()
Dim pilist As PropertyInfo() = t.GetProperties

[Code].....

View 7 Replies

Compare Nullable Types In WHERE Clause Of Linq To Sql .NET?

May 4, 2012

I am trying to query for records where that column IS NULL:

Dim UnassignedSubSvc =
From c In CurrentContext.SubService
Where c.Product.ProductSubServiceId **is null**
Select c).ToList()

View 1 Replies

Distinct Values In LINQ With Anonymous Types

Jul 2, 2011

Supposing the referenced List below contains 2 elements:
Dim Countries = From c In List _
Select New With { .Country = c.Country, .CountryID = c.CountryID }

The code above returns
.Country=Spain .CountryID = 1
.Country=Spain .CountryID = 1

How can I get the distinct values? The Countries query should contain only
.Country=Spain .CountryID = 1

View 5 Replies

LINQ Returning List Of Anonymous Types

Mar 11, 2009

Any best approach to what I'm trying to achieve (linq to sql, returning list of data to show in a grid/list etc etc)... Its complaining about anonymous type conversion, and from what I'm reading, thats not elegant way of doing it.

Public Function GetHistory(ByVal historyId As Integer) As List(Of ?????????)
Using dc As New myDataContext(Application.GetConnection)
Return (From t In dc.ActionTypes, a In t.MyTable Where a.HistoryID = historyId Select a.ActionOn, a.ActionBy, t.Description, a.ImpactedItem, a.ActionDescription).ToList
End Using
End Function

View 4 Replies

LINQ: Creating Objects Of Anonymous Types?

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

Linq Grouping With Anonymous Types And Option Strict

Apr 24, 2012

I've got the below, where I'm grouping a collection by a propery, then wanting to access the properties of my group. Problem I have is with the anonymous typing. Because of option strict I have to give an explicit type but I can't work out what the type should be. The below doesn't compile because t.HeadAccountKey isn't a value (as t has a type of object). So either I need do some casting or my linq selector is wrong,

[Code]....

View 1 Replies

Use Linq To Entities To Group A Collection Without Using Anonymous Types?

Apr 24, 2012

The documentation has an example about grouping on multiple properties[code]...

Is it possible to rewrite the original query to just return IEnumerable(Of CustomerRegionGroup), or do I have to use the anonymous type, and run a second query on the result of the first?

View 1 Replies

What's Equivalent Syntax For Anonymous Types In A LINQ Statement

Jun 29, 2010

I'm trying to translate some C# LINQ code into VB.NET and am stuck on how to declare an anonymous type in VB.NET.[code]How do you translate C#'s new { ... } syntax into VB.NET?

View 2 Replies

Cannot Iterate Of A Collection Of Anonymous Types Created From A LINQ Query?

Mar 17, 2010

Every LINQ example I have seen for VB.NET anonymous types claims I can do something like this:

[code]...

Now when I go to iterate through the collection(see example below), I get an error that says "Name "x" is not declared. For Each x in Infos It's like VB.NET doesn't understand that Infos is a collection of anonymous types created by LINQ and wants me to declare "x" as some type. (Wouldn't this defeat the purpose of an anonymous type?) I have added the references to System.Data.Linq and System.Data.DataSetExtensions to my project. Here is what I am importing with the class:

[code]...

View 4 Replies

VS 2010 Upgrade From 2008 To 2010 - Now LINQ - IntelliSense Is Not Working For LINQ Stuff

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

Error 1 Operator '&' Is Not Defined For Types 'String' And 'System.Xml.Linq.XElement'

May 17, 2012

i am downloading data from xml using linq library those data i want to add them on a textblock item

TextBlock1.Text = TextBlock1.Text & result

but it has an error :

Error 1 Operator '&' is not defined for types 'String' and 'System.Xml.Linq.XElement'.

When i am changing this line to :

TextBlock1.Text = TextBlock1.Text & result.Tostring

it works but it adds this data :

"<"data> data <"/data>

instead of :

hello

View 1 Replies

Linq Not Working After .Net 2.0 To 3.5?

Jan 15, 2012

I started developing an application several weeks ago and decided today that I may want to use LINQ. So I changed my project from .NET Framework 2.0 to 3.5 and restarted the program. However, I can not get the most basic LINQ statement to work. I thought it was my code until I started a blank .NET 3.5 project and inserted the basic code (below) which worked without issue. So I then started another .NET 2.0 project and inserted the code (which I knew wouldn't work) and the errors are the same as the project that I converted. So next I converted this new .NET 2.0 to 3.5 and the code still doesn't work. So migrating from 2.0 to 3.5 isn't working for LINQ.

My question is: If one changes from a .NET 2.0 to a .NET 3.5 how do they get LINQ to work properly?

[Code]...

View 2 Replies

.net - Linq To AD Query Not Working?

Sep 20, 2011

user.fld_usr_name is a string with the value random name user is an object that is given as a parameter

ByVal user As GUser

this is the linq query that doesn't work

Dim result = (From usr In users Where usr.Name.Contains(user.fld_usr_name) Select usr).ToList()

this is the one that works

Dim result = (From usr In users Where usr.Name.Contains("random name") Select usr).ToList()

this is the error

Object reference not set to an instance of an object.

I am using this in Linq to Active Directory library which probably means it's linq to entities I've tried everything?

View 3 Replies

Asp.net - LINQ Intellisense Stopped Working?

Feb 13, 2010

What happend to my Intellisense?When I type a line like this ...

Dim users = (From u In Membership.GetAllUsers Select u.UserName)

I get (almost) no Intellisense when I get to the Select u. part. Only Equals, GetHashCode, GetType, ReferenceEquals and ToString appears. Not "UserName" and the other relevant propeties of the MembershipUser class.The code compiles and works just fine.

View 2 Replies

Asp.net - Serialize Linq Objects Not Working?

Apr 14, 2010

Using the following code:

Private Sub MakeMeSomeXmlBeforeRyanGetsAngry()
Dim db As New MyDBDataContext
Dim customer = From c In db.Customers Select c

[code]....

I am attempting to serialize my linq collection of customers. But it keeps throwing

Type 'System.Data.Linq.DataQuery`1[MyDB.Customer]' cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute. See the Microsoft .NET Framework documentation for other supported types. My issue is that I have already marked the dbml Serialization Mode to UniDirectional and when I check the dbml codebehind all of the DataContract()> and DataMember()> elements are there. I have tried adding various dataloadoptions and setting deferredloading to false, but no luck.

View 2 Replies

LINQ To SQL Update Not Working Correctly

May 11, 2009

I use the following statement to position which row to update;
Dim salonToUpdate = (From r In db.Salons _
Where r.StoreID = storeID _
Select r).Single()
If fileDate = #1/1/1900# OrElse fileDate = Nothing Then
SalonToUpdate.LastDownLoadDate = TableDate
[Code] .....

I've double checked to make sure none of the dates are invalid or null, but when the bolded statement executes, the following sql runs through the trace:
exec sp_executesql N'UPDATE [dbo].[Salons]
SET [LastDownLoadDate] = @p0
WHERE 0 = 1',N'@p0 datetime',@p0='2008-01-04 00:00:00:000'
Of course it's going to fail if LINQ is passing in where 0=1 every time. Shouldn't it be using some unique row identifier, (in my case, the salon id), to update the specific row?

View 2 Replies

Make The Code Working Without LINQ?

May 15, 2012

I have this code to get images width and height from header file without full loading the image..I convert it automatically from C# to VB.NET by [url]....The source C# code here:http:[url]....

Now I need this code to work with .net framework 2.The code doesn't work after converting even with .NET 3.5

Imports System.Collections.Generic
Imports System.Drawing
Imports System.IO[code]..........

View 3 Replies

.net - AndAlso In VB Linq Query Doesn't Seem To Be Working?

Sep 14, 2010

The below query fails with Null Reference Exception when there are elements in BOMIDs where MatID property is nothing.I thought the 'x.MatID isnot Nothing AndAlso' would prevent the x.MatID.Process part of the where from being executed. There are a couple elements in the BOMIDs collection that where MatID is nothing.

From x In BOMIDs _
Group Join y As PurchasedProcess In SpecialProcesses _
On x.MatID.PurchasedProcess Equals y.Name _
Into G = Group _

[code]....

View 2 Replies

How To Make CustomClass Save Changes Working In LINQ

Sep 26, 2011

I am trying to get Linq going on. I have a CustomClass named Ordr with the properties OrderID, EmployeeID, _ShipRegion

I do a simple query:
Dim query = From c In dbcontext.Orders _
Where c.EmployeeID = 2
Select New Ordr With { _
.OrderID = c.OrderID, _
.EmployeeID = c.EmployeeID, _
.Shipregion = c.ShipRegion}

Then I bind this query to a DataGridView:
DataGridView1.DataSource = query

Now, when I try to save any changes with dbcontext.SaveChanges() no changes are saved. OrderID is the primary key. How was I supposed to do it properly without loosing the ability to save changes?

View 1 Replies

Join Doesn't Working In LINQ In Devexpress XPO

Nov 23, 2011

I have used persistance class and used following LINQ query.[code]but it throws an error saying. "Specified Method is not Supported".How can i get data from two table using XPO Persistance Class?

View 1 Replies

Linq Query On Dictionary<TKey, TValue> Working As DataSource?

Dec 21, 2010

I have the following in VB:

Dim sources = From source In importSources Select New With _
{.Type = source.Key, .Source = source.Value.Name}
dgridSourceFiles.DataSource = sources

[code]....

View 2 Replies

Working With System.collection.generic.Ienumerable/XML Linq Queries?

Oct 22, 2009

This is really a continuation from my earlier post. I've never worked with this datatype/collection (system.collection.generic.Ienumerable) before so I'm struggling to declare the query globally so I can reference the results within other sub routines/functions. I also am struggling to convert it to other types.how I can convert the collection of xml elements/system.collection.generic.Ienumerable into an xmltextreader (I know I will have to change the query below as it select the value of the node and not the node itself) I imagine by converting the query result to system.IO.stream My first port of call was MSDN but I find the material very difficult to understand for this particular subject.

[Code]...

View 3 Replies

.net - Working With The ObjectQuery Single Enumeration Challenge In Linq-To-Entities Entity SQL?

Dec 30, 2011

I'm working on modifying this example:

Using advWorksContext As New AdventureWorksEntities
' Call the constructor that takes a command string and ObjectContext.
Dim productQuery1 As New ObjectQuery(Of Product)("Product", advWorksContext)

[code]....

An ObjectQuery can be enumberated only once. (Subsequent attempts at enumeration throw an exception.) The enumberation takes place in the for each statement. The problem is that if the query is empty attempting a For Each will throw an exception. But if I check for a count:If productQuery1.Count > 0 Then . . .

That eats up my one chance at enumeration. I could nest the For Each in a try/catch block and throw away the empty query exceptions, but that's ugly.

View 2 Replies

C# :: Determining Object Equivalence For Value Types, Reference Types And ILists?

Nov 1, 2009

I have a class with a Property called 'Value' which is of type Object.Value can be of any type, a structure, a class, an array, IList etc.My problem is with the setter and determining whether the value has changed or not.This is simple enough for value types, but reference types and lists present a problem.For a class, would you assume that the Equals method has been implemented correctly, or just assume that the value has changed every time the setter is called?If I did assume it's changed, then perhaps I should assume it for value types as well, so that the behaviour is consistent.

View 2 Replies

Compare Two Types In Dictionary Of Types .net?

Jun 23, 2012

I need to compare two dictionary values if the types stored are equal, this is what i have

if gettype(Args(key)) = gettype(argtypes(key)) then
'' do something
end if

[Code]....

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







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