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


ADVERTISEMENT

Which As Clause To Use With Anonymous Type With Option Strict On

Aug 10, 2010

Consider the requirement to always declare Option Strict On. We'll always need to declare variables with the As keyword. What would be the type of an anonymous type?Example : Dim product As ... = New With { Key .Name = "paperclips", .Price = 1.29 }

View 2 Replies

Linq And Option Strict - "Option Strict On Disallows Late Binding"

Jun 30, 2011

[Code]...

I really prefer to keep Option Strict On. the proper way to do this?

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

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

Option Strict - Error Option Strict On Disallows Implicit Conversions From 'Object' To 'XtremeCalendarControl.CalendarControl'

Oct 17, 2009

How can I get round this error: Option Strict On disallows implicit conversions from

[Code]...

View 4 Replies

LINQ With Option Strict

May 26, 2012

I'm facing a trick issue with LINQ. I generate the above code:[code..]

Everything is running well if I turn off Option Explicit. When I turn it on, compiler is showing me a meessage: Expression is of type 'Object', which is not a collection type. Referencing to lResult variable.

View 1 Replies

Option Strict On LINQ

Dec 28, 2011

i'm encountering the following problem. I recently activated 'Option Strict On' and now I get an error in my LINQ query. From e As TEnum returns the following error: Option Strict On disallows implicit conversions from 'Object' to 'TEnum'. [code]

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

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

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

LINQ And Option Strict When Using Custom Object?

Aug 12, 2011

http://127.0.0.1:47873/help/1-6644/ms.help?method=page&id=C318B79A-FA4D-4DE3-B62D-C1162BEB267E&product=VS&productVersion=100&topicVersion=100&locale=EN-US&topicLocale=EN-US
and i get the following error

[code].....

View 3 Replies

Fixing LINQ Query To Be Compatible With Option Strict On

Nov 23, 2011

I am in the process of fixing my code to be in line with Option Strict On, but the code below is still throwing an error and I don't know why. What do you think?

[Code]...

View 4 Replies

Use System.Linq Extension Method In Project With Option Strict ON?

Feb 2, 2011

I'm using .NET 3.5 In my DataLayer class I have references of System.Core,System.Data.Linq, System.Data.DataSetExtensions. But I cantnot use this feature in Linq query if I have Option Strict ON:

[Code]...

View 1 Replies

Tools To Convert Option Strict Off Code Into Option Strict On?

Mar 28, 2010

I have to take over a project written in vb.net, which contains more than 400k lines of code written in option strict off mode. I want to build it under option strict on first before I do anything else -- which maybe converting it into C#. I found there's thousands of lines of code raises compilation error, mostly are about implicit type casts. Is there any tool would help to make it compile under option strict on mode if I don't want to correct every single line manually? Because it's really painful to add CStr/CInt invocation into every line of Code myself.

View 3 Replies

Option Strict On - Error On All The ".Cells" Lines Saying Option Strict On Disallows Late Binding

Sep 7, 2010

I turned Option Strict On and i get an error on all the ".Cells" lines saying option strict on disallows late binding.

a = 1
b = 3
c = 2
d = 1
With oSheet

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

View 4 Replies

Linq Query Has An Implicit Cast Error For DataGridViewRow When Option Strict Is Enabled?

Jul 6, 2009

I have a DataGridView that is bound to a list of objects called "BaseChange". The BaseChange objects are made up of 4 properties...

ChangeType
ChangeStatus
ChangeDescription
LastChangeDate

The datagridview has columns for all 4 values as well as a 5th (a checkbox column called "colIsSelected"). There is no problem binding the list to the grid and displaying the items. The problem is that the query that gets the selected items in the grid is giving me an implicit cast error when option strict is enabled.

This is the query...

Dim _changes As List(Of BaseChange)
_changes = (From _row As DataGridViewRow In dgvChanges.Rows() _
Where Convert.ToBoolean(_row.Cells(NAME_COLUMN_IS_SELECTED).Value) = True _
Select DirectCast(_row.DataBoundItem, BaseChange)).ToList()

...and it produces the correct results with option strict off. The implicit cast squiggle is on the "row As DataGridViewRow" code, and the full message is "Implicit conversion from 'Object' to 'System.Windows.Forms.DataGridViewRow'*".

If I exclude the "As DataGridViewRow" from the query, I get a late binding error on the _row.Cells and _row.DataBoundItem and this also fails option strict.I need this to work with Option Strict enabled, and in VB.

View 1 Replies

Option Strict Is Off, Compile Fail With "Option Strict On"?

Apr 13, 2011

I have inherited a VB.NET application that I need to compile so I can run dorkumentation on it. I first received "Option Strict On disallows implicit conversion from x to y" errors, so I turned off the Option Strict option in the Project file.

So why do I still fail with the same error message?

View 2 Replies

Set Option Explicit And Option Strict On A Project / Solution Level?

Feb 22, 2011

I really like the coding speed that vb.net provides, but I don't like the possibility to forget to declare variable types, return types of functions, etc. and that is why in each class I use[code]..

Is there a way to define those two options on the project/solution level?

View 2 Replies

VS 2005 Option Explicit On; Option Strict On

Feb 24, 2010

what does these two code means in vb.net: Option Explicit on Option strict on i think option explicit means the compiler is not going to do any kind of conversion and i need to do all of them by the code;also it becomes case sensitive i.e;

[Code]...

View 8 Replies

Use Of Option Strict And Option Infer

Feb 22, 2011

1. I have read that keeping Option strict on and Option infer off is good practice and will insure your code is tight and properly written. I would like input regarding this, pro's and con's from those who are in the know.

2. Having said that, I have set Option strict on and Option infer off in an existing program I wrote (that was working perfectly mind you) with them off and on respectively. I went through and cleaned up all the errors on the 'need AS' and casting of variables, but one is leaving me a bit put out.[code]

I have also read where using My.Computer.System.Directory.GetFiles() instead of System.IO.Directory.GetFiles() is probably not a good thing, but when I change to this I get no error, but also no dataI am thinking I should stay with the strict on and infer off but am really slogging through getting this code correct.Running Win7 on Dual Quad Core XEON Intel Extreme with 8Gb RAM.

View 2 Replies

C# - Are Anonymous Types Slower

Dec 30, 2010

Are anonymous types slower than declarative types?

For example, does

Dim score as Double = CalculateScore()

run slower than

Dim score = CalculateScore()

Why use explicit typing if it's no slower?

View 5 Replies

Return And Use An Anonymous Types?

Sep 5, 2009

Assuming Anonymous Types are tailored to be used with LINQ, I'd like to use them for simply and fast data aggregation without an explicit class definition, like in this snippet[code]....

View 2 Replies

Convert Anonymous Type To Strong Type For Grouping Query?

Aug 30, 2010

I've pieced together some information from other posts but I'm stuck. The first part works fine. Basically I query the database using LINQ and then I loop through the results generating a report.

[Code]...

View 2 Replies

How To Do This With Option Strict On

Nov 25, 2010

Dim frm As mshtml.HTMLFormElement
Dim sel As mshtml.HTMLSelectElement
Dim hi As mshtml.IHTMLElementCollection
Dim inp As mshtml.HTMLInputElement

[code].....

Looks to me that childnodes object has a more specific type. But what? Not ihtmlcollection. The type support some item interface.

View 3 Replies

Option Strict - On Or Off?

Dec 7, 2009

Title says it all really, should I have it off unless I'm having an error, or simply have it on all the time?

View 10 Replies







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