can someone help me pls, im new to vb.net and im trying to work through the nhibernate firstsolution sample (written in c# re-posted here http://blogs.hibernatingrhinos.com/nhibernate/archive/2008/04/01/your-first-nhibernate-based-application.aspx as thier site is down again) and im struggling to convert this one bit. ive tried numerous convertors; telerik, developerfusion and a several others but none of the code produced will compile and i cant see the why...
if you search for this method youll find where im upto...
private readonly Product[] _products = new[]
{
new Product {Name = "Melon", Category = "Fruits"},
new Product {Name = "Pear", Category = "Fruits"},
new Product {Name = "Milk", Category = "Beverages"},
new Product {Name = "Coca Cola", Category = "Beverages"},
new Product {Name = "Pepsi Cola", Category = "Beverages"},
};
' just the next part of the tutorial, ive resolved the "var" in vb.net 2005 bit np
private void CreateInitialData()
{
using(ISession session = _sessionFactory.OpenSession())
using(ITransaction transaction = session.BeginTransaction())
{
foreach (var product in _products)
session.Save(product);
transaction.Commit();
}
}
since my c# and vb are both shakey at best ive tried to use several conversion utils/sites.
developer fusion gives:
Private ReadOnly _products As Product() = New () {New Product(), New Product(), New Product(), New Product(), New Product()}
telerik gives
Private ReadOnly _products As Product() = New () {New Product() With { _
.Name = "Melon", _
.Category = "Fruits" _
}, New Product() With { _
.Name = "Pear", _
.Category = "Fruits" _
}, New Product() With { _
.Name = "Milk", _
.Category = "Beverages" _
}, Nw Product() With { _
.Name = "Coca Cola", _
.Category = "Beverages" _
}, New Product() With { _
.Name = "Pepsi Cola", _
.Category = "Beverages" _
}}
which seems the most useful except it complains about a type expected here "New () {..." ive tried various things including the missing type in the New() as suggested in the comments but just cant figure it out... what am i missing? am i just being dumb? or isnt there and equivilent?
This is all the code i have, as it is a simple copy n paste from the tutorial c# to the convertor sites. in the mean time ive used the developer fusion definition and manually populated the array elements in aother method. i.e.
Private _products As Product() = {New Product(), New Product(), New Product(), New Product(), New Product()}
Private Sub CreateInitialData()
' =================
' since i couldnt figure out how to convert the initialisation of the
' "_products" array/collections whatever it is, i cheated and did this,
' seems to work ok though probably poor practice
With _products(0)
.Name = "Melon"
.Category = "Fruits"
End With
' etc....
End Sub
background if it matters: vs2005, .net 2.0
Cheers all