udana
udana

Reputation: 1

C# -Version Linq to Sql

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# ?

Upvotes: 0

Views: 131

Answers (3)

erikkallen
erikkallen

Reputation: 34401

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)

Upvotes: 0

Dennis C
Dennis C

Reputation: 24747

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)
                     )
            );

Upvotes: 0

Kieran
Kieran

Reputation: 18059

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
}

Upvotes: 1

Related Questions