tags:

views:

51

answers:

4

From Linq to Sql i received the code (VB version)

Dim db as New DBDSDataContext

Dim products
            =_ 
               <Products>
                   <%=From product in db.Products_
                   Select_
                <Product>
                     <ProductName>
                          <%=product.ProductName %>
                     </ProductName>
                          <QuantityPerUnit>
                             <%=product.QuantityPerUnit%>
                           </QuantityPerUnit>
                      </Product>
                   </Products>

1) I do not know VB.Please help me to know the equal C# code of the above.

2) Any Utility is available to know VB to C# ?

+1  A: 
DBSDataContext db = new DBSDataContext();
var products = from p in db.Products
select p;

I am not sure if that is the select statement that you want... That will return an IEnumerable of Products.

foreach(Product prod in products){
//do something
}
Kieran
A: 

I am sorry I don't have a VS on hand, but it should looks like this in C#. (not test and not verified)

var products =new XElement("Products",
                   from product in db.Products
                   select new XElement("Product",
                     new XElement("ProductName",
                          product.ProductName),
                     new XElement("QuantityPerUnit",
                          product.QuantityPerUnit)
                     )
            );
Dennis Cheung
A: 

Use Reflector for such issues in the future.

ssg
A: 

C# does not have XML literals, so there is no equivalent (except for building the XML using the the classes in the System.Xml namespace)

erikkallen