I am using the Expression Editor with a XAML I am modifying. I am trying to use an expression like...
ProjectsToBuild.Select(x=>x.Replace("$VERSION", TrunkVersion).ToArray()
...where ProjectsToBuild is of type string[].
The XAML editor complains that ...
How do I use Linq to transform ProjectsToBuild to what I need? I think the VB.NET syntax is the same as C# correct?
Related
How do I get the Type of a Lambda using Visual Basic?
SyntaxKind.FunctionLambdaHeader,
SyntaxKind.MultiLineFunctionLambdaExpression,
SyntaxKind.MultiLineSubLambdaExpression,
SyntaxKind.SingleLineFunctionLambdaExpression,
SyntaxKind.SingleLineSubLambdaExpression,
SyntaxKind.SubLambdaHeader
I am not sure I need to deal with all 6 above
I want to be able to add an As Clause to variable declarations like below.
Dim startPointGetter = Function(part As EnvDTE.vsCMPart) arg.GetStartPoint(part)
I don't even know how I would specify the As Clause manually so I need some help.
To figure out the type, at least, you can use SemanticModel.GetSymbolInfo to figure out the underlying type.
I'm trying to use Excel-DNA to integrate my VB.NET DLL into VBA. But I'm running into the following problem. If I try to add this line before one of my static (Shared) class functions:
<ExcelFunction(Description = "Do stuff", Category = "Useful functions")> _
I get a compile error saying "Name 'Description' is not declared" (and same for Category). I've got VS2005 so maybe that has something to do with it. The example given in the Excel-DNA documentation is for C# and I'm feeling that maybe I just need to get the syntax right.
I've got the needed
Imports ExcelDna.Integration
line at the beginning of my file.
The syntax for using attributes in VB.NET is a bit different to C#. You need to write the property assignments with ":=", something like this:
<ExcelFunction(Description:="Do Stuff", Category:="Useful functions")>_
...
The MongoDB C# driver supports queries on Nullable(Of T) according to this Jira ticket:
https://jira.mongodb.org/browse/CSHARP-483
However, I am having issues getting it working.
mycol.AsQueryable.Where(Function(p) p.MyNullableInteger = 3)
As instructed, I removed the .Value property from the query, however that breaks strict typing, so I had to remove my Option Strict On clause. It then compiled successfully however I would ideally like that clause back in.
The PredicateTranslator is throwing an exception as follows:
Unsupported where clause: (Boolean)(p.MyNullableInteger == (Nullable)3)
The actual Where clause expression generated by .NET is:
p => Convert((p.MyNullableInteger == ConvertChecked(3)))
I am using driver 1.5. My POCO class does register a classmap but the mapping does not reference the property here (it is just setting representation from String to ObjectId for my Id property).
Turns out this is only a bug in Visual Basic. It works fine in C#. I have created a Jira here: https://jira.mongodb.org/browse/CSHARP-542.
I'm also going to edit your question tags to include VB as opposed to c#.
We have a LINQ-to-SQL datacontext with some int columns we want to map to Enum values. This is in VB.NET and we tried the "Global." prefix trick that works in C#, where global:: maps a field to an enum [see other StackOverflow references on this].
The problem is that SQL metal doesn't generate the code properly for VB.NET and instead creates code like this:
Private _OrderStatusID As [Global].Anvil.Mobile.MobileOrderStates
This won't compile so we have to manually fix by removing the brackets so that the generated code compiles. If we remove the Global. prefix we get the DBML1005 Anyone know a fix/workaround?
Using VB.net, the following snippet gives the error below.
Dim _account = Account.Find(Function(x As Account) x.AccountName = txtFilterAccountName.Text)
or similarly if I do
.SingleOrDefault (Function(x As Account) x.AccountName = txtFilterAccountName.Text)
will both give the error "The method 'CompareString' is not supported". If I make the same call searching for an integer (ID field) it works fine.
.SingleOrDefault (Function(x As Account) x.Id = 12)
So integer matching is fine but strings don't work Is this a problem with the VB.net templates?
No this is not a problem with Vb.Net templates.
The problem is that you are not using a normal LINQ provider. Based on your tag (subsonic) I'm guessing you're using a LINQ to SQL query.
The problem is that under the hood, this is trying to turn your code into an expression tree which is then translated into an SQL like query. Your project settings are turning your string comparison into a call in the VB runtime. Specifically, Microsoft.VisualBasic.CompilerServices.Operators.CompareString.
The LINQ2SQL generater in question or VB compiler (can't remember where this check is done off the top of my head) does not understand how to translate this to an equivalent bit of SQL. Hence it generates an error. You need to use a string comparison function which is supported by LINQ2SQL.
EDIT Update
It looks like the CompareString operator should be supported in the Linq2SQL case. Does subsonic have a different provider which does not support this translation?
http://msdn.microsoft.com/en-us/library/bb399342.aspx
The problem is with SubSonic3's SQL generator and the expression tree generated from VB.NET.
VB.NET generates a different expression tree as noted by JaredPar and SubSonic3 doesn't account for it - see Issue 66.
I have implemented the fix as described but it has yet to merge into the main branch of SubSonic3.
BlackMael's fix has been committed:
http://github.com/subsonic/SubSonic-3.0/commit/d25c8a730a9971656e6d3c3d17ce9ca393655f50
The fix solved my issue which was similar to John Granade's above.
Thanks to all involved.