Skip to content

Instantly share code, notes, and snippets.

@serkanince
Created October 9, 2019 07:33
Show Gist options
  • Save serkanince/506bd3507d866082231069af4346bfb2 to your computer and use it in GitHub Desktop.
Save serkanince/506bd3507d866082231069af4346bfb2 to your computer and use it in GitHub Desktop.
ef code-first
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; }
}
}
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; }
}
}
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