Answered by:
Help convert Linq To Sql C# to VB please

Question
-
Hi
I would really appreciate it if someone could convert this code to vb so I can use it in my project.
Thank You
Here is the code:
[WebMethod]
public List<Task> GetTasks()
{
// Create a collection to hold the results
List<Task> colResult = new List<Task>();
RIATasksDBDataContext DB = new RIATasksDBDataContext();
var colTasks = from Tasks in DB.Tasks
where Tasks.UserID == GetCurrentUserID()
select Tasks;
// Loop thru the Tasks
foreach (var item in colTasks)
{
// Create a Task
Task tmpTask = new Task();
// Set only the TaskID and the Name
// We do this because Description could be
// a large amount of data that will slow down
// the application and we don't need it now
tmpTask.TaskID = item.TaskID;
tmpTask.TaskName = item.TaskName;
// Add to the final results
colResult.Add(tmpTask);
}
return colResult;
}Thank You again
Saturday, June 11, 2011 4:44 PM
Answers
-
Hi mutlyp;
Something like this should be what it translate to.
Public Function GetTasks() As List(Of Task) ' Create a collection to hold the results Dim colResult As List(Of Task) = New List(Of Task)() Dim DB As New RIATasksDBDataContext() Dim colTasks = From Tasks In DB.Tasks Where Tasks.UserID == GetCurrentUserID() Select Tasks ' Loop thru the Tasks For Each item in colTasks ' Create a Task Dim tmpTask As Task = New Task() ' Set only the TaskID and the Name ' We do this because Description could be ' a large amount of data that will slow down ' the application and we don't need it now tmpTask.TaskID = item.TaskID tmpTask.TaskName = item.TaskName ' Add to the final results colResult.Add(tmpTask) Next Return colResult End Function
Fernando
If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".- Proposed as answer by Tim Copenhaver Thursday, June 16, 2011 4:27 PM
- Marked as answer by Larcolais Gong Monday, June 27, 2011 9:46 AM
Saturday, June 11, 2011 5:39 PM
All replies
-
Hi mutlyp;
Something like this should be what it translate to.
Public Function GetTasks() As List(Of Task) ' Create a collection to hold the results Dim colResult As List(Of Task) = New List(Of Task)() Dim DB As New RIATasksDBDataContext() Dim colTasks = From Tasks In DB.Tasks Where Tasks.UserID == GetCurrentUserID() Select Tasks ' Loop thru the Tasks For Each item in colTasks ' Create a Task Dim tmpTask As Task = New Task() ' Set only the TaskID and the Name ' We do this because Description could be ' a large amount of data that will slow down ' the application and we don't need it now tmpTask.TaskID = item.TaskID tmpTask.TaskName = item.TaskName ' Add to the final results colResult.Add(tmpTask) Next Return colResult End Function
Fernando
If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".- Proposed as answer by Tim Copenhaver Thursday, June 16, 2011 4:27 PM
- Marked as answer by Larcolais Gong Monday, June 27, 2011 9:46 AM
Saturday, June 11, 2011 5:39 PM -
Any update? Would you mind letting us know how it goes?
Best Regards,
Larcolais Gong[MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Monday, June 13, 2011 8:57 AM -
public List<Task> GetTasks(){RIATasksDBDataContext DB = new RIATasksDBDataContext();var colTasks = from Tasks in DB.Taskswhere Tasks.UserID == GetCurrentUserID()select new Task{askID = Tasks.TaskID,TaskName = Tasks.TaskName};return colTasks.ToList();}I think your code can update like this
Best Regards,
If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".Monday, June 13, 2011 11:31 AM