Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

How to use entity framework 7 in RC 2?

$
0
0

I have dbcontext class.

 public class ApplicationDbContext : DbContext
    {
        public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options)
        {
        }
        public DbSet<VH> Vhs { get; set; }
    }

Now I want to use it in controller. I have to pass an argument to the constructor.

 [HttpGet("{id}")]
        public string Get(string id)
        {
            return GetBlockId(id);
        }

        private string GetBlockId(string btn)
        {
            var optionsBuilder = new DbContextOptionsBuilder<ApplicationDbContext>();
            using (ApplicationDbContext context = new ApplicationDbContext(optionsBuilder.Options))
            {
            }
        }

However I already define 

optionsBuilder 

in Startup.cs

 public void ConfigureServices(IServiceCollection services)
 {
          services.AddDbContext<ApplicationDbContext>(options=>options.UseSqlServer("Data Source=something;Initial Catalog=Master;User ID=sa;password=xxxx;Application Name=Validation"));

            services.AddMvc();
 }


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>