Doubt about the Context Class

Asked

Viewed 58 times

-1

In my system I have class Context to make the connection with the Bank, through the Entity Framework and I have a doubt, I should only use the public DbSet<NomedaClasse> Classe {get; set;} if I’m doing my system by default Code First or can I use it normally? Sorry to ask, I’m new to programming!

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Data.Entity;
using CadastroAtivos.Models;

namespace CadastroAtivos.DAL
{
    public class clsContext : DbContext
    {
        public clsContext() : base ("name=Stringconexao"){}

        public DbSet<clsMarcaModel> dbMarcas { get; set; }

        public DbSet<clsModeloModel> dbModelos { get; set; }
  • 2

    What is it to use normally? because it should always use normally, never irregularly. If you are new to programming you must first learn the basics, the basics, so you can understand the rest. Although it may seem that you are managing to do something, without understanding everything that is happening there from your base may be doing everything wrong and you are not even able to notice the mistakes. There is no novice messing with EP, at least not with property, so it is better to go back a few steps before.

  • 1

    You can set up a Context and point it out as a single connection key on your web.config

2 answers

2


DbSet<T> are the interpretation through objects of the tables of your database, regardless of how was the approach of the implementation of its context, be it Database First or Code First.

If you still don’t know enough about Entityframework, try to understand it better by accessing the Entity documentation:

http://www.entityframeworktutorial.net/what-is-entityframework.aspx

1

In the case of an EF Database First, there is also a context, which is automatically generated and updated every time you update the EDMX template.

  • 1

    Excuse the question, what would EDMX be?

  • 1

    EDMX is an XML file and usually edited in a graphical interface, which reflects the structure of the database.

  • 1

    https://stackoverflow.com/a/41599350/10991202

Browser other questions tagged

You are not signed in. Login or sign up in order to post.