This is a migrated thread and some comments may be shown as answers.

List(Of T) WITH... error

1 Answer 26 Views
Code Converter
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Ivan
Top achievements
Rank 1
Ivan asked on 21 Apr 2012, 08:31 PM
I am converting the tutorial located at http://www.asp.net/web-forms/tutorials/aspnet-45/getting-started-with-aspnet-45-web-forms/create_the_data_access_layer so I can understand it. In converting the script:
using System.Collections.Generic;
using System.Data.Entity;
  
namespace WingtipToys.Models
{
    public class ProductDatabaseInitializer : DropCreateDatabaseIfModelChanges<ProductContext>
    {
        protected override void Seed(ProductContext context)
        {
            GetCategories().ForEach(c => context.Categories.Add(c));
            GetProducts().ForEach(p => context.Products.Add(p));
        }
  
        private static List<Category> GetCategories()
        {
            var categories = new List<Category> {
                new Category
                {
                    CategoryID = 1,
                    CategoryName = "Cars"
                },
                new Category
                {
                    CategoryID = 2,
                    CategoryName = "Planes"
                },
                new Category
                {
                    CategoryID = 3,
                    CategoryName = "Trucks"
                },
                new Category
                {
                    CategoryID = 4,
                    CategoryName = "Boats"
                },
                new Category
                {
                    CategoryID = 5,
                    CategoryName = "Rockets"
                },
            };
  
            return categories;
        }
  
        private static List<Product> GetProducts()
        {
            var products = new List<Product> {
                new Product
                {
                    ProductID = 1,
                    ProductName = "Convertible Car",
                    Description = "This convertible car is fast! The engine is powered by a neutrino based battery (not included)."
                                  "Power it up and let it go!"
                    ImagePath="carconvert.png",
                    UnitPrice = 22.50,
                    CategoryID = 1
               },
                new Product 
                {
                    ProductID = 2,
                    ProductName = "Old-time Car",
                    Description = "There's nothing old about this toy car, except it's looks. Compatible with other old toy cars.",
                    ImagePath="carearly.png",
                    UnitPrice = 15.95,
                     CategoryID = 1
               },
                new Product
                {
                    ProductID = 3,
                    ProductName = "Fast Car",
                    Description = "Yes this car is fast, but it also floats in water.",
                    ImagePath="carfast.png",
                    UnitPrice = 32.99,
                    CategoryID = 1
                },
                new Product
                {
                    ProductID = 4,
                    ProductName = "Super Fast Car",
                    Description = "Use this super fast car to entertain guests. Lights and doors work!",
                    ImagePath="carfaster.png",
                    UnitPrice = 8.95,
                    CategoryID = 1
                },
                new Product
                {
                    ProductID = 5,
                    ProductName = "Old Style Racer",
                    Description = "This old style racer can fly (with user assistance). Gravity controls flight duration."
                                  "No batteries required.",
                    ImagePath="carracer.png",
                    UnitPrice = 34.95,
                    CategoryID = 1
                },
                new Product
                {
                    ProductID = 6,
                    ProductName = "Ace Plane",
                    Description = "Authentic airplane toy. Features realistic color and details.",
                    ImagePath="planeace.png",
                    UnitPrice = 95.00,
                    CategoryID = 2
                },
                new Product
                {
                    ProductID = 7,
                    ProductName = "Glider",
                    Description = "This fun glider is made from real balsa wood. Some assembly required.",
                    ImagePath="planeglider.png",
                    UnitPrice = 4.95,
                    CategoryID = 2
                },
                new Product
                {
                    ProductID = 8,
                    ProductName = "Paper Plane",
                    Description = "This paper plane is like no other paper plane. Some folding required.",
                    ImagePath="planepaper.png",
                    UnitPrice = 2.95,
                    CategoryID = 2
                },
                new Product
                {
                    ProductID = 9,
                    ProductName = "Propeller Plane",
                    Description = "Rubber band powered plane features two wheels.",
                    ImagePath="planeprop.png",
                    UnitPrice = 32.95,
                    CategoryID = 2
                },
                new Product
                {
                    ProductID = 10,
                    ProductName = "Early Truck",
                    Description = "This toy truck has a real gas powered engine. Requires regular tune ups.",
                    ImagePath="truckearly.png",
                    UnitPrice = 15.00,
                    CategoryID = 3
                },
                new Product
                {
                    ProductID = 11,
                    ProductName = "Fire Truck",
                    Description = "You will have endless fun with this one quarter sized fire truck.",
                    ImagePath="truckfire.png",
                    UnitPrice = 26.00,
                    CategoryID = 3
                },
                new Product
                {
                    ProductID = 12,
                    ProductName = "Big Truck",
                    Description = "This fun toy truck can be used to tow other trucks that are not as big.",
                    ImagePath="truckbig.png",
                    UnitPrice = 29.00,
                    CategoryID = 3
                },
                new Product
                {
                    ProductID = 13,
                    ProductName = "Big Ship",
                    Description = "Is it a boat or a ship. Let this floating vehicle decide by using its "
                                  "artifically intelligent computer brain!",
                    ImagePath="boatbig.png",
                    UnitPrice = 95.00,
                    CategoryID = 4
                },
                new Product
                {
                    ProductID = 14,
                    ProductName = "Paper Boat",
                    Description = "Floating fun for all! This toy boat can be assembled in seconds. Floats for minutes!"
                                  "Some folding required.",
                    ImagePath="boatpaper.png",
                    UnitPrice = 4.95,
                    CategoryID = 4
                },
                new Product
                {
                    ProductID = 15,
                    ProductName = "Sail Boat",
                    Description = "Put this fun toy sail boat in the water and let it go!",
                    ImagePath="boatsail.png",
                    UnitPrice = 42.95,
                    CategoryID = 4
                },
                new Product
                {
                    ProductID = 16,
                    ProductName = "Rocket",
                    Description = "This fun rocket will travel up to a height of 200 feet.",
                    ImagePath="rocket.png",
                    UnitPrice = 122.95,
                    CategoryID = 5
                }
            };
  
            return products;
        }
    }
}


Using your converter, I get:

Imports System.Collections.Generic
Imports System.Data.Entity
 
Namespace WingtipToys.Models
    Public Class ProductDatabaseInitializer
        Inherits DropCreateDatabaseIfModelChanges(Of ProductContext)
        Protected Overrides Sub Seed(context As ProductContext)
            GetCategories().ForEach(Function(c) context.Categories.Add(c))
            GetProducts().ForEach(Function(p) context.Products.Add(p))
        End Sub
 
        Private Shared Function GetCategories() As List(Of Category)
            Dim categories = New List(Of Category)() With { _
                New Category() With { _
                    .CategoryID = 1, _
                    .CategoryName = "Cars" _
                }, _
                New Category() With { _
                    .CategoryID = 2, _
                    .CategoryName = "Planes" _
                }, _
                New Category() With { _
                    .CategoryID = 3, _
                    .CategoryName = "Trucks" _
                }, _
                New Category() With { _
                    .CategoryID = 4, _
                    .CategoryName = "Boats" _
                }, _
                New Category() With { _
                    .CategoryID = 5, _
                    .CategoryName = "Rockets" _
                } _
            }
 
            Return categories
        End Function
 
        Private Shared Function GetProducts() As List(Of Product)
            Dim products = New List(Of Product)() With { _
                New Product() With { _
                    .ProductID = 1, _
                    .ProductName = "Convertible Car", _
                    .Description = "This convertible car is fast! The engine is powered by a neutrino based battery (not included)." + "Power it up and let it go!", _
                    .ImagePath = "carconvert.png", _
                    .UnitPrice = 22.5, _
                    .CategoryID = 1 _
                }, _
                New Product() With { _
                    .ProductID = 2, _
                    .ProductName = "Old-time Car", _
                    .Description = "There's nothing old about this toy car, except it's looks. Compatible with other old toy cars.", _
                    .ImagePath = "carearly.png", _
                    .UnitPrice = 15.95, _
                    .CategoryID = 1 _
                }, _
                New Product() With { _
                    .ProductID = 3, _
                    .ProductName = "Fast Car", _
                    .Description = "Yes this car is fast, but it also floats in water.", _
                    .ImagePath = "carfast.png", _
                    .UnitPrice = 32.99, _
                    .CategoryID = 1 _
                }, _
                New Product() With { _
                    .ProductID = 4, _
                    .ProductName = "Super Fast Car", _
                    .Description = "Use this super fast car to entertain guests. Lights and doors work!", _
                    .ImagePath = "carfaster.png", _
                    .UnitPrice = 8.95, _
                    .CategoryID = 1 _
                }, _
                New Product() With { _
                    .ProductID = 5, _
                    .ProductName = "Old Style Racer", _
                    .Description = "This old style racer can fly (with user assistance). Gravity controls flight duration." + "No batteries required.", _
                    .ImagePath = "carracer.png", _
                    .UnitPrice = 34.95, _
                    .CategoryID = 1 _
                }, _
                New Product() With { _
                    .ProductID = 6, _
                    .ProductName = "Ace Plane", _
                    .Description = "Authentic airplane toy. Features realistic color and details.", _
                    .ImagePath = "planeace.png", _
                    .UnitPrice = 95.0, _
                    .CategoryID = 2 _
                }, _
                New Product() With { _
                    .ProductID = 7, _
                    .ProductName = "Glider", _
                    .Description = "This fun glider is made from real balsa wood. Some assembly required.", _
                    .ImagePath = "planeglider.png", _
                    .UnitPrice = 4.95, _
                    .CategoryID = 2 _
                }, _
                New Product() With { _
                    .ProductID = 8, _
                    .ProductName = "Paper Plane", _
                    .Description = "This paper plane is like no other paper plane. Some folding required.", _
                    .ImagePath = "planepaper.png", _
                    .UnitPrice = 2.95, _
                    .CategoryID = 2 _
                }, _
                New Product() With { _
                    .ProductID = 9, _
                    .ProductName = "Propeller Plane", _
                    .Description = "Rubber band powered plane features two wheels.", _
                    .ImagePath = "planeprop.png", _
                    .UnitPrice = 32.95, _
                    .CategoryID = 2 _
                }, _
                New Product() With { _
                    .ProductID = 10, _
                    .ProductName = "Early Truck", _
                    .Description = "This toy truck has a real gas powered engine. Requires regular tune ups.", _
                    .ImagePath = "truckearly.png", _
                    .UnitPrice = 15.0, _
                    .CategoryID = 3 _
                }, _
                New Product() With { _
                    .ProductID = 11, _
                    .ProductName = "Fire Truck", _
                    .Description = "You will have endless fun with this one quarter sized fire truck.", _
                    .ImagePath = "truckfire.png", _
                    .UnitPrice = 26.0, _
                    .CategoryID = 3 _
                }, _
                New Product() With { _
                    .ProductID = 12, _
                    .ProductName = "Big Truck", _
                    .Description = "This fun toy truck can be used to tow other trucks that are not as big.", _
                    .ImagePath = "truckbig.png", _
                    .UnitPrice = 29.0, _
                    .CategoryID = 3 _
                }, _
                New Product() With { _
                    .ProductID = 13, _
                    .ProductName = "Big Ship", _
                    .Description = "Is it a boat or a ship. Let this floating vehicle decide by using its " + "artifically intelligent computer brain!", _
                    .ImagePath = "boatbig.png", _
                    .UnitPrice = 95.0, _
                    .CategoryID = 4 _
                }, _
                New Product() With { _
                    .ProductID = 14, _
                    .ProductName = "Paper Boat", _
                    .Description = "Floating fun for all! This toy boat can be assembled in seconds. Floats for minutes!" + "Some folding required.", _
                    .ImagePath = "boatpaper.png", _
                    .UnitPrice = 4.95, _
                    .CategoryID = 4 _
                }, _
                New Product() With { _
                    .ProductID = 15, _
                    .ProductName = "Sail Boat", _
                    .Description = "Put this fun toy sail boat in the water and let it go!", _
                    .ImagePath = "boatsail.png", _
                    .UnitPrice = 42.95, _
                    .CategoryID = 4 _
                }, _
                New Product() With { _
                    .ProductID = 16, _
                    .ProductName = "Rocket", _
                    .Description = "This fun rocket will travel up to a height of 200 feet.", _
                    .ImagePath = "rocket.png", _
                    .UnitPrice = 122.95, _
                    .CategoryID = 5 _
                } _
            }
 
            Return products
        End Function
    End Class
End Namespace
 
'=======================================================
'Service provided by Telerik (www.telerik.com)
'Conversion powered by NRefactory.
'Twitter: @telerik, @toddanglin
'Facebook: facebook.com/telerik
'=======================================================


Visual Studio 11 errors lies in the line:

Dim categories = New List(Of Category)() With { _
If I change the WITH to a FROM, VS11 removes the error warnings.
 

1 Answer, 1 is accepted

Sort by
0
Tsvetoslav
Telerik team
answered on 25 Apr 2012, 12:23 PM
Hi Ivan,

Our converter is not perfect - I must admit. Errors are possible and  your observation is correct. Unfortunately, we no longer support it. Here is another one that you might use to double check your result.
http://www.developerfusion.com/tools/convert/csharp-to-vb/

Regards,
Tsvetoslav
the Telerik team

Consider using RadControls for ASP.NET AJAX (built on top of the ASP.NET AJAX framework) as a replacement for the Telerik ASP.NET Classic controls, See the product support lifecycle here.

Tags
Code Converter
Asked by
Ivan
Top achievements
Rank 1
Answers by
Tsvetoslav
Telerik team
Share this question
or