Best way to access a SQL Server database using C# .Net

后端 未结 5 1401
隐瞒了意图╮
隐瞒了意图╮ 2020-12-15 07:13

I am new to .NET and have heard about several different ways of querying a SQL Server databse such as ADO.NET and the entity framework.

Can anyone give me some advis

5条回答
  •  南方客
    南方客 (楼主)
    2020-12-15 07:55

    LINQ to SQL is pretty easy to work with. You can drag and drop your database tables into the designer and write pretty simple queries in a few minutes.

        NorthwindDataContext db = new NorthwindDataContext();
    
        var products = from p in db.Products
                       select p;
    

    Which would basically translate into SELECT * FROM Products

    A few other select samples:

        var products = from p in db.Products
                       where p.Category.Name == "Beverages"
                       select p;
    
        var products = from p in db.Products
                       orderby p.Name
                       select p;
    

提交回复
热议问题