ADO.NET Entity Framework or ADO.NET

前端 未结 3 1926
予麋鹿
予麋鹿 2021-02-15 23:42

I\'m starting a new project based on ASP.NET and Windows server.

The application is planned to be pretty big and serve large amount of clients p

3条回答
  •  日久生厌
    2021-02-16 00:14

    My advice is use both. At first I thought I would only use linq to sql and never have to touch ado.net ever again ( what made me happy lol).

    Now I am using both because some things linq to sql(and any ORM like EF) can't do. I had to do some mass inserts and I did it first with linq to sql and to do 500 records it took over 6mins(2 mins for validation rules rest was inserting into the db).

    I changed it to sql bulk copy and now it is down to 2min and 4 seconds(4 seconds to do all inserts)

    But like marc_s said I really did not want to fiddle around with DataTables, DataRows, and untyped Row["RowName"].

    Say my table was like 10 columns long and called Table A. What I did was I used linq to sql and made a Table A class( new TableA()) object and populated it with data. I then would pass this object to a method that created the datarow.

    So linq to sql saved me some time because I probably would have made a class as I would not have wanted to pass in 10 parameters into the method that makes the data row. I also feel it gives a bit of typeness back as you have to pass in the right object to use that method so less chance of passing in the wrong data.

    Finally you can still use linq to sql to call Stored procedures and that is like one line of code.

    So I would use both when ever you notice that linq to sql (or in your case EF) is slow then just write a SP and call it through EF. If you need to do straight ado.net evaluate what you need to do maybe you can use EF for most of the code(so you can at least work with objects) and only for that small portion ado.net sort of what I did with sql bulk copy.

提交回复
热议问题