locked
Create a modelBuilder.Entity with StoredProcedure RRS feed

  • Question

  • User-507786106 posted

    How do I create a modelBuilder.Entity with SQL StoredProcedure for my AspNetUser Table.

    I want to update one or two field values in a record, and I do not know how to create a modelBuilder.Entity with StoredProcedure that is specific the the one stored procedure. This applies to one table only. I don't know how use MapToStoredProcedures... my storedProcedure Name is : AspNetUsers_Update_PhoneNumber

    Please help with this issue, as I am new to MVC Entity.... Kindly thank you very much.

    Thursday, March 30, 2017 1:52 PM

All replies

  • User-707554951 posted

    Hi slimbunny,

    By default. Code first will configure all enetities to perform insert, update and delete commands using direct table access.

    However, In EF6, we could configure your code first model to use store produce for some or all entities in your model.

    Something as below:

      protected override void OnModelCreating(DbModelBuilder modelBuilder)
            {
                base.OnModelCreating(modelBuilder);
                modelBuilder
         .Entity<Your entity>()
         .MapToStoredProcedures();
    
            }

    For more information, please refer to the following links:

    https://msdn.microsoft.com/en-us/data/dn468673.aspx

    https://msdn.microsoft.com/en-us/library/dn468673(v=vs.113).aspx

    Best regards

    Cathy

    Friday, March 31, 2017 2:54 AM