Giter Site home page Giter Site logo

patricksouza27 / crud-entityframeworkcore Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 1.0 9 KB

O Entity Framework (EF) é um framework de mapeamento objeto-relacional (ORM) desenvolvido pela Microsoft. Ele permite que os desenvolvedores trabalhem com dados de bancos de dados relacionais usando objetos e classes em vez de escrever consultas SQL diretas. O EF é uma parte essencial do .NET

Home Page: https://balta.io/carreiras/desenvolvedor-backend-dotnet

C# 100.00%
entity-framework entity-framework-core orm sql

crud-entityframeworkcore's Introduction

Entity Framework Core is a modern object-database mapper for .NET. It supports LINQ queries, change tracking, updates, and schema migrations. EF Core works with many databases, including SQL Database (on-premises and Azure), SQLite, MySQL, PostgreSQL, and Azure Cosmos DB.

Microsoft.EntityFrameworkCore Microsoft.EntityFrameworkCore.SqlServer Microsoft.Data.SqlClient.Design

Docker e SQL Server 2019 / Azure Data Studio.

Controller

public static class CursoController
    {
        public static void ExcluirCurso(DataContext context, Curso curso)
            => context.Cursos.Remove(curso);
        public static List<Curso> ListarCurso(DataContext context)
            => context.Cursos.AsNoTracking().Include(x=> x.Categoria).ToList();
        public static void UpdateCurso(DataContext context, Curso curso)
            => context.Cursos.Update(curso);
        public static void AdicionarCurso(DataContext context, Curso curso)
            => context.Cursos.Add(curso);
    }

Mapeamento

[Table("Categoria")]
    public class Categoria
    {
        [Key][DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public int Id { get; set; }
        [Required]
        [MaxLength(20)]
        [Column("Name", TypeName = "NVARCHAR")]
        public string Name { get; set; }

        public Categoria() { }
        public Categoria(string name)
        => Name = name;

        
        public override string ToString()
            => "|\t " + Id + " - "+ Name + " \t |";

        public void SalvarCategoria(DataContext context) => CategoriaController.AdicionarCategorias(context, this); 

        public void Update(DataContext conection, string name)
        {
            Name = name;
            CategoriaController.UpdateCategorias(conection, this);
        }
    }
[Table("Curso")]
    public class Curso
    {
        [Key][DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public int Id { get; set; }

        [Required]
        [MaxLength(20)]
        [Column("Name", TypeName = "NVARCHAR")]
        public string Name { get; set; }

        [ForeignKey("CategoriaId")]
        public int CategoriaId { get; set; }
        public Categoria Categoria { get; set; }

        public Curso() { }
        public Curso(string name, Categoria categoria)
        {
            Name = name;
            Categoria = categoria;
        }
        public override string ToString()
         => "| \t" + Id + " - " + Name + " - " + Categoria.Name;


        public void AdicionarCurso(DataContext datacontext) => CursoController.AdicionarCurso(datacontext, this);

crud-entityframeworkcore's People

Contributors

patricksouza27 avatar

Watchers

 avatar

Forkers

adriel-loopes

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.