-
-
Save nihat-js/f8badbc67dde21be76482497b20f2b8a to your computer and use it in GitHub Desktop.
Entity framework very very simple tutotrial with SQL Server Connection String
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// See https://aka.ms/new-console-template for more information | |
using Microsoft.EntityFrameworkCore; | |
Console.WriteLine("Hello, World!"); | |
var context = new ApplicationContext(); | |
var users = context.Users.ToList(); | |
foreach (var user in users) { | |
Console.WriteLine(user.Name + " " + user.Surname + " => " + user.Email); | |
} | |
public class ApplicationContext : DbContext { | |
public DbSet<User> Users { get; set; } | |
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { | |
optionsBuilder.UseSqlServer( | |
"Server= localhost;Database=nihat;User Id=sa;Password=123456;Trusted_Connection=True;TrustServerCertificate=True;" | |
); | |
} | |
} | |
public class User { | |
public int Id { get; set; } | |
public string Name { get; set; } | |
public string Surname { get; set; } | |
public string Email { get; set; } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment