Created
December 4, 2017 03:19
-
-
Save shunnien/322025689e25c3d6c873ace22cb692d8 to your computer and use it in GitHub Desktop.
Dapper Contrib keys demo
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