Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entity Framework Core in Full .Net?

Is There Any Way To Implement Entity Framework Core In Full .Net Framework Console Application?

like image 449
mohammad kamali Avatar asked Nov 21 '16 09:11

mohammad kamali


People also ask

Can we use Entity Framework core in NET Framework?

You can use EF Core in APIs and applications that require the full . NET Framework, as well as those that target only the cross-platform .

Is Entity Framework core part of .NET Core?

Entity Framework Core (EF Core) is the latest version of the Entity Framework from Microsoft. It has been designed to be lightweight, extensible and to support cross platform development as part of Microsoft's . NET Core framework.

What is .NET Core entity framework?

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.

Is .NET 5.0 framework or core?

NET 5 is the next major release of . NET Core following 3.1. We named this new release .


1 Answers

First you need to create console application with full .net framework, Second install these packages using package manager console,

Install-Package Microsoft.EntityFrameworkCore.SqlServer
Install-Package Microsoft.EntityFrameworkCore.Tools –Pre

Now you need to create your model and context

namespace ConsoleEfCore
{
    class Program
    {
        static void Main(string[] args)
        {
            MyContext db = new MyContext();
            db.Users.Add(new User { Name = "Ali" });
            db.SaveChanges();
        }
    }
    public class MyContext : DbContext
    {
        public DbSet<User> Users { get; set; }
        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            optionsBuilder.UseSqlServer(@"Server=.;Database=TestDb;Trusted_Connection=True;");
        }
    }
    public class User
    {
        public int Id { get; set; }
        public string Name { get; set; }
    }
}

then just need to use this command

Add-Migration initial

and then you need to update your database to create that

Update-Database

run project and you we'll see User would insert to your database

like image 149
Ali Khalili Avatar answered Nov 15 '22 12:11

Ali Khalili