locked
Is EF Necessary? RRS feed

  • Question

  • User-1240188151 posted

    Hi!

    I'm (finally) moving from WebForms to .Core.

    I'm using a current project from work as a test. This project is using a 3rd party SQL Server database.  It's rather large and complicated, and when one user is added, a good 10 tables at least are updated.  I have to use a lot of their SPs and several lines of my own code to make it do what I want when we add a new user.

    I see EF being used everywhere, but I'm beginning to wonder that in such a situation, is it better to simply stick with accessing the DB like I've been doing over the years, or is this something easily convertible to use with EF.  Thanks!

    Sunday, February 12, 2017 11:56 AM

All replies

  • User-1509636757 posted

    mwinner

    is it better to simply stick with accessing the DB like I've been doing over the years

    I assume that you might be using ADO.NET or any wrapping library (like Microsoft data access components). Since you are moving from WebForms to Core, suggested is to use Entity Framework if you are still going to use SQL Server. Core is an evolving framework, and I believe something that is being explored or new like technology; will work smoother with related latest tools. A Basic example like, mostly today you will be dealing with Generics, Collections, Lists for database table objects to represent records, that is more easy with EF (rather than getting DataSet, DataTable or DataReader using ADO.NET and to use them in Core framework). Just a thought. hope that make sense.

    Edit: for main question: Is EF Necessary: EF in this case is a choice, not a compulsion. You might be interested referring this somewhat related thread, if you want to rely on ADO in Core: asp.net - Is ADO.NET in .NET Core possible?

    Sunday, February 12, 2017 1:11 PM
  • User-1240188151 posted

    Thanks for the reply.

    How difficult is it to learn EF?  I have to balance work & learning, so I also need to take into account how long it will take to learn.

    Sunday, February 12, 2017 5:19 PM
  • User-1509636757 posted

    It is easy if you are already familiar with LinQ queries, and you will be able to perform most of backend operation for most application scenarios.

    Sunday, February 12, 2017 5:22 PM
  • User-821857111 posted

    How difficult is it to learn EF?
    Depends on how good a learner you are. EF Core is easier to learn than previous versions because they rewrote it from scratch and simplified it quite a bit. You can also execute raw SQL commands using EF Core, including stored procedures.

    Monday, February 13, 2017 2:20 PM
  • User-1240188151 posted

    Interesting!  Haven't seen this one.

    Thanks!

    Monday, February 13, 2017 2:29 PM
  • User-832373396 posted

    Hi mwinner,

    If you like to write sql in asp.net core application.

    I suggest that you could use EF method like code below:

    public class Core02062Controller : Controller
        {
            private readonly ApplicationDbContext _context;
            public Core02062Controller(ApplicationDbContext context)
            {
                _context = context;    
            }
            public async Task<IActionResult> Index()
            {
                 _context.Database.ExecuteSqlCommand("select * from Table");
                  _context.Database.ExecuteSqlCommandAsync("select * from Table");
    ..
    }

    Or use Dapper : https://github.com/StackExchange/Dapper    ,  it also can execute a query and map the results to a strongly typed List;

    Best regards,

    Jolie

    Tuesday, February 21, 2017 8:33 AM
  • User1108898723 posted

    You can use NReco.Data: this is lightweight, high-performance micro-ORM library for .NET Core, like Dapper but better; for example, you can use abstract dynamic queries instead of composing SQL queries in the code, define app-level SQL dataviews etc. It allows you to create-retrieve-update-delete rows with DTO, Dictionary or RecordSet (this is structure very similar to DataTable/DataRow that currently is not available in .NET Core). 

    NReco.Data can be used in addition to EF Core: MVC app example with EF Core + NReco.Data.

    I'm the author of this library and you can ask me any technical questions if something is not clear.

    Sunday, March 12, 2017 7:58 AM