Skip to content

Instantly share code, notes, and snippets.

@nihat-js
Created August 16, 2024 08:06
Show Gist options
  • Save nihat-js/f8badbc67dde21be76482497b20f2b8a to your computer and use it in GitHub Desktop.
Save nihat-js/f8badbc67dde21be76482497b20f2b8a to your computer and use it in GitHub Desktop.
Entity framework very very simple tutotrial with SQL Server Connection String
// 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