Created
January 15, 2013 19:33
-
-
Save muratg/4541318 to your computer and use it in GitHub Desktop.
This file contains hidden or 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.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using System.Data.Entity; | |
namespace MyApplication | |
{ | |
public class MyEntity | |
{ | |
public int Id { get; set; } | |
public string Name { get; set; } | |
public static MyEntity CreateEntity() | |
{ | |
return new MyEntity { Name = "Test - " + DateTime.Now }; | |
} | |
} | |
public class MyCtx : DbContext | |
{ | |
public MyCtx() { } | |
public DbSet<MyEntity> TestEntities { get; set; } | |
} | |
public static class MyTest | |
{ | |
public static string SimpleWrite() | |
{ | |
var entity = MyEntity.CreateEntity(); | |
using (var db = new MyCtx()) | |
{ | |
db.TestEntities.Add(entity); | |
db.SaveChanges(); | |
} | |
return "Saved entity " + entity.Name; | |
} | |
} | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
MyTest.SimpleWrite(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment