Last active
December 4, 2017 03:18
-
-
Save shunnien/f63486a52e63225660a60dad6f12ba4d to your computer and use it in GitHub Desktop.
Entity Framework v6 Composite keys Annotation
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
void Main() | |
{ | |
string connstr = @"data source=(LocalDb)\MSSQLLocalDB;initial catalog=Northwind;Integrated Security=True;application name=EntityFramework"; | |
var entity = new NorthwindEntities(connstr); | |
var regionInstance = entity.Regions.Take(2).Dump(); | |
var OrderDetailsInstance = entity.OrderDetails.Take(2).Dump(); | |
} | |
public class NorthwindEntities : DbContext | |
{ | |
public DbSet<Regions> Regions { get; set; } | |
public DbSet<OrderDetails> OrderDetails { get; set; } | |
public NorthwindEntities() | |
: base("name=NorthwindEntities") | |
{ | |
} | |
public NorthwindEntities(string nameOrConnectionString) : base(nameOrConnectionString) | |
{ | |
} | |
} | |
// Define other methods and classes here | |
[Table("Region")] | |
public class Regions | |
{ | |
[Key] | |
public int RegionID { get; set; } | |
public string RegionDescription { get; set; } | |
} | |
[Table("Order Details")] | |
public class OrderDetails | |
{ | |
[Key] | |
[Column(Order = 1)] | |
public int OrderID { get; set; } | |
[Key] | |
[Column(Order = 2)] | |
public int ProductID { get; set; } | |
public decimal UnitPrice { get; set; } | |
public short Quantity { get; set; } | |
public float Discount { get; set; } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment