static void Main(String[] args) { String cs = @"Data Source=ALIASTVALK;Initial Catalog=TestEF;Integrated Security=True; MultipleActiveResultSets=True"; using (TestEFContext c = new TestEFContext(cs)) { c.objects.Add(new CObj { Id = 1, SomeCol = "c" }); c.SaveChanges(); } IEnumerable <String> ks = new List <String> { String.Format("{0,10}-c", 1) }; foreach (var k in ks) { Console.WriteLine(k); } using (TestEFContext c = new TestEFContext(cs)) { var vs = from o in c.objects where ks.Contains(SqlFunctions.StringConvert((Decimal?)o.Id, 10) + "-" + o.SomeCol) select o; foreach (var v in vs) { Console.WriteLine(v.Id); } } }
static void Main(string[] args) { String cs = @"Data Source=ALIASTVALK;Initial Catalog=TestEF;Integrated Security=True; MultipleActiveResultSets=True"; using (TestEFContext ctx = new TestEFContext(cs)) { Console.WriteLine("The value is " + ctx.Users.Count().ToString()); } }
static void Main(string[] args) { String cs = @"Data Source=ALIASTVALK;Initial Catalog=TestEF;Integrated Security=True; MultipleActiveResultSets=True"; using (TestEFContext ctx = new TestEFContext(cs)) { ctx.Movies.Add(new Movie { Title = "avatar" }); ctx.SaveChanges(); } using (TestEFContext ctx = new TestEFContext(cs)) { Console.WriteLine(ctx.Movies.Count()); } try { using (TestEFContext ctx = new TestEFContext(cs)) { Movie m = new Movie { Id = 1 }; //ctx.Movies.Attach(m); ctx.Movies.Remove(m); ctx.SaveChanges(); } } catch (Exception ex) { Console.WriteLine(ex.Message); } using (TestEFContext ctx = new TestEFContext(cs)) { Console.WriteLine(ctx.Movies.Count()); } using (TestEFContext ctx = new TestEFContext(cs)) { Movie m = new Movie { Id = 1 }; ctx.Movies.Attach(m); ctx.Movies.Remove(m); ctx.SaveChanges(); } using (TestEFContext ctx = new TestEFContext(cs)) { Console.WriteLine(ctx.Movies.Count()); } }