Giter Site home page Giter Site logo

asp.net_framework_api_rc2's Introduction

Asp.Net_Framework_API_RC2

####Add DataContext class

    public class DataContext: DbContext
    {
        public DataContext(DbContextOptions<DataContext> options)
            : base(options)
        { }
        protected override void OnModelCreating(ModelBuilder builder)
        {
            base.OnModelCreating(builder);
            
            // Customize the ASP.NET Identity model and override the defaults if needed.
            builder.Entity<User>(u =>
            {
                u.Property<string>("FirstName").HasMaxLength(50).IsRequired();
                u.Property<string>("LastNamePrefix").HasMaxLength(20);
                u.Property<string>("LastName").HasMaxLength(50).IsRequired();
                u.Property<int>("Age").HasMaxLength(3).IsRequired();
            });
            
            // For example, you can rename the ASP.NET Identity table names and more.
            // Add your customizations after calling base.OnModelCreating(builder);
            
        }

        public DbSet<User> Users { get; set; } // TODO: Add User class
    }
    

For more: Entity Framework Code First Migrations

####Add connection string to appsetting.json

"Data": {
    "DefaultConnection": {
      "ConnectionString": "Server=WINDOWS10\\SQLEXPRESS;Database=AC_DB_01;Trusted_Connection=True;MultipleActiveResultSets=true;"
    }
    }

####Add to StartUp ConfigureServices

services.AddDbContext<DataContext>(options =>
            options.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"]));

####Tools ‣ Nuget Package Manager ‣ Package Manager Console

PM> Install-Package Microsoft.EntityFrameworkCore.Tools -Pre

####Add 'Microsoft.EntityFrameworkCore.Tools' to the 'tools' section in project.json

"Microsoft.EntityFrameworkCore.Tools": {
      "version": "1.0.0-preview1-final",
      "imports": [
        "portable-net45+win8+dnxcore50",
        "portable-net45+win8"
      ]
    }
PM> Add-Migration -OutputDir 01_DataAccess\Migrations FirstMigration

To undo this action, use Remove-Migration

//everytime you change the Db, create a new Migration(Add-Migration Migrations_addUserLastname) and Update-Database.
//To remove the last Migration do PM> Remove-Migration
PM> Update-Database

For more Microsoft PM Comand Line , see the Package Manager Console (Visual Studio).

ASP.NET Core Application to New Database.

asp.net_framework_api_rc2's People

Contributors

petervanhemert avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.