티스토리 뷰
728x90
반응형
Web.config
<?xml version="1.0"?>
<configuration>
<connectionStrings>
<add name="MyContext" connectionString="Server=localhost;Database=MyDatabase;User ID=sa;Password=your_password" providerName="Microsoft.EntityFrameworkCore.SqlServer" />
</connectionStrings>
</configuration>
DbContext
using Microsoft.EntityFrameworkCore;
namespace MyApp
{
public class MyContext :DbContext
{
public MyContext(DbContextOptions options) : base(options)
{
}
public DbSet<User> Users { get; set; }
public DbSet<Product> Products { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlServer(Configuration["connectionStrings:MyContext"]);
}
}
}
OR
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
namespace MyApp
{
public class MyContext : DbContext
{
public MyContext(DbContextOptions options) : base(options)
{
}
public DbSet<User> Users { get; set; }
publicDbSet<Product> Products { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
IConfiguration configuration = new ConfigurationBuilder()
.AddJsonFile("appsettings.json")
.Build();
optionsBuilder.UseSqlServer(configuration["connectionStrings:MyContext"]);
}
}
}
using Microsoft.EntityFrameworkCore;
namespace MyApp
{
public class MyContext : DbContext
{
public MyContext(DbContextOptions options) : base(options)
{
}
public DbSet<User> Users { get; set; }
public DbSet<Product> Products { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<User>().HasKey(u => u.Id);
modelBuilder.Entity<User>().Property(u => u.Name).IsRequired();
modelBuilder.Entity<User>().Property(u => u.Email).IsRequired();
modelBuilder.Entity<Product>().HasKey(p => p.Id);
modelBuilder.Entity<Product>().Property(p => p.Name).IsRequired();
modelBuilder.Entity<Product>().Property(p => p.Price).IsRequired();
}
}
}
using MyApp;
namespace MyApp
{
public class Program
{
public static void Main(string[] args)
{
using (var context = new MyContext())
{
var user = new User { Name = "John Doe", Email = "test000@example.com" };
var product = new Product { Name = "Apple iPhone 12", Price = 1000 };
context.Users.Add(user);
context.Products.Add(product);
context.SaveChanges();
}
}
}
}
modelBuilder.Entity().HasDbFunction(ef => ef.Function("MyProcedure"));
using (var context = new MyContext())
{
var result = context.MyProcedure(param1, param2, param3);
}
OR
using (var context = new MyContext())
{
var result = context.MyProcedure();
var value = result.FirstOrDefault();
}
728x90
반응형
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
TAG
- error-java
- jstl(java standard tag library)-core
- 인텔리제이(intellij)
- 스프링 프레임워크(spring framework)
- docker
- java 키워드 정리
- MainActor
- java-개발 환경 설정하기
- 표현 언어(expression language)
- await
- 스프링 프레임워크(spring framewordk)
- .submit()
- 제품 등록
- 특정 문자를 기준으로 자르기
- 메이븐(maven)
- jstl(java standard tag library)
- 스프링 시큐리티(spring security)
- 진수 변환
- jsp 오픈 소스
- 람다식(lambda expression)
- system.io
- 스프링 시큐리티(spring security)-http basic 인증
- java.sql
- nl2br
- 문자 자르기
- React
- java web-mvc
- REST API
- In App Purchase
- System.Diagnostics
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
글 보관함