none
How to create and use dbcontext RRS feed

  • Question

  • I’m new to entity framework. I have created class library project DAL and create model from an existing database but then I stuck there.

    I don’t now know how to use what they call context in order to perform CRUD operation.

    Please I need someone help to push me so I can move and continue my learning journey from that point.

    I’m using EF 6, VS 2013 and VB.NET

    Kind regards.


    Samijf

    Tuesday, July 8, 2014 6:50 PM

Answers

All replies

  • The dbcontext is being shown to you in the link.

    http://www.telerik.com/help/wpf/consuming-data-linq-to-ado-net-entity-data-model.html

    You can also use a "Using" statement to create the dbcontext and let the "Using" statement do the Dispose() for you. Otherwise, if you are using the example in the first link, then you should do a dbcontext.Dispose() yourself in code.

    http://msdn.microsoft.com/en-us/library/htd05whh.aspx

    Tuesday, July 8, 2014 8:07 PM
  • I meant Microsoft EF6 not Telerik.

    Samijf

    Tuesday, July 8, 2014 8:45 PM
  • What I want is once I created the EF model what is the next step to interact with the model and be able to perform CRUD operations.

    Samijf

    Tuesday, July 8, 2014 9:00 PM
  • I meant Microsoft EF6 not Telerik.

    I don't care if the EF example on how to use the dbContext is in some Telerik example or not.

    That's how the dbContext is used in doing CRUD ooperations with EF using the dbContext-- period.

    It doesn't matter if you are using it in the DAL or in some UI code, becuase that's how it's done.

    Dim dbContext As New NorthwindEntities() Dim query = From p In dbContext.ProductSet _ Where p.Categories.CategoryName = "Seafood" _ Select p Dim products As IEnumerable(Of Product) = query.ToList()

    dbContext.Dispose();

    You create the dbContext from the EntityModel, you query, add, update or delete objects off of the virtual model within

    the scope of the dbContext.

    OR

    Using dbContext As New NorthwindEntities
        ' Insert code to work with resource.
    End Using

    It doesn't take a rocket scientist to figure it out.

    Tuesday, July 8, 2014 9:09 PM
  • What I want is once I created the EF model what is the next step to interact with the model and be able to perform CRUD operations

    You shouldn't talk about a Data Access Layer (DAL) until you figure out the basics.

    http://www.vbforums.com/showthread.php?540421-Tutorial-An-Introduction-to-the-ADO-NET-Entity-Framework

    • Marked as answer by Samijf Sunday, July 13, 2014 12:33 AM
    Tuesday, July 8, 2014 11:09 PM