Created
October 9, 2019 07:33
-
-
Save serkanince/506bd3507d866082231069af4346bfb2 to your computer and use it in GitHub Desktop.
ef code-first
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
using Microsoft.EntityFrameworkCore; | |
using System; | |
using System.Collections.Generic; | |
using System.Text; | |
namespace Sample | |
{ | |
public sealed class AzureDBContext : DbContext | |
{ | |
public AzureDBContext(DbContextOptions<AzureDBContext> options) : base(options) | |
{ | |
} | |
public DbSet<SehirEntity> Sehir { get; set; } | |
public DbSet<IlceEntity> Ilce { get; set; } | |
} | |
} |
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
using System; | |
using System.Collections.Generic; | |
using System.ComponentModel.DataAnnotations; | |
using System.ComponentModel.DataAnnotations.Schema; | |
using System.Linq; | |
using System.Threading.Tasks; | |
namespace Sample | |
{ | |
public class IlceEntity | |
{ | |
[Key] | |
public int id { get; set; } | |
public int sehirId { get; set; } | |
[ForeignKey("sehirId")] | |
public SehirEntity sehir { get; set; } | |
public string isim { get; set; } | |
} | |
} |
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
using System; | |
using System.Collections.Generic; | |
using System.ComponentModel.DataAnnotations; | |
using System.ComponentModel.DataAnnotations.Schema; | |
using System.Linq; | |
using System.Threading.Tasks; | |
namespace Sample | |
{ | |
public class SehirEntity | |
{ | |
[Key] | |
public int id { get; set; } | |
[Required] | |
public string isim { get; set; } | |
public virtual ICollection<IlceEntity> ilceler { get; set; } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment