Print Page | Close Window

Help with C# translation

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=2013
Printed Date: 19-Sep-2025 at 2:36am


Topic: Help with C# translation
Posted By: rclarke
Subject: Help with C# translation
Date Posted: 27-Jul-2010 at 1:11pm
Can someone please show me the VB translation for the following C# line of code:
 
QueryFilters.AddFilter<User>(q => q.Where(u => u.UserName == Principal.Identity.Name));
I tried using InstantVB which does not produce the correct translation:
QueryFilters.AddFilter(Of User)(Function(q) q.Where(Function(u) u.UserName = Principal.Identity.Name))

Any help would be greatly appreciated.



Replies:
Posted By: GregD
Date Posted: 28-Jul-2010 at 2:25pm
Not sure, but it looks like the InstantVB translation may be missing a pair of parentheses: 
 
THIS:
     QueryFilters.AddFilter(Of User)(Function(q) (q.Where(Function(u) u.UserName = Principal.Identity.Name))) 
 
NOT THIS:
     QueryFilters.AddFilter(Of User)(Function(q) q.Where(Function(u) u.UserName = Principal.Identity.Name))


Posted By: rclarke
Date Posted: 28-Jul-2010 at 3:24pm
Thanks For trying to help Greg but your suggestion did not fix the problem. In fact I get the same error any time I try
 
aUser = pManager.Users.Where(Function(u) u.UserName = pUsername).FirstOrNullEntity()
The error is "Overloaded resolution failed because no accessable 'Where' can be called with these arguements.
I have tried a number of translators and all of them translate the C# code with the same result. So several translators think 
that the VB code is correct yet it does not work, very frustrating...


Posted By: davidklitzke
Date Posted: 28-Jul-2010 at 3:52pm
Perhaps you are missing an "Imports" statement.  See:
 
http://www.ideablade.com/forum/forum_posts.asp?TID=1743&PID=6615#6615 - http://www.ideablade.com/forum/forum_posts.asp?TID=1743&PID=6615#6615


Posted By: rclarke
Date Posted: 28-Jul-2010 at 4:15pm
The proper imports are there and the Where does show up with all of the overloads of which there are 4. There has to be something about how the parameters are specified at least that's what the compiler is complaining about. I guess I'll just rewrite the queries as LINQ queries and not try to use the Lambda expressions but it would be nice of I could figure this out and use the Lambda's


Posted By: rclarke
Date Posted: 28-Jul-2010 at 4:42pm
Problem Solved! I refreshed my model from the database and regenerated and the problem went away. Funny thing is that I had made no database changes. I don't know what caused the original propblem but I'm good now. Thanks to all for the help.



Print Page | Close Window