static void Main(string[] args) { TestEntities test = new TestEntities(); var user = test.tblUsers.CreateObject(); Console.WriteLine(user.Surname); // Prints Smith }
public static List <SourceTable1> LoadDataToList() { using (var context = new TestEntities()) { var records = (from r in context.SourceTable1 select r);// context.SourceTable1.Select(r =>r.col1 != null); // from b in context.TargetTable1 select b; return(records.AsEnumerable <SourceTable1>().ToList()); } }
public NavigationMenuViewModel() { // use cmd to create files // C:\Windows\Microsoft.NET\Framework64\v4.0.30319>datasvcutil.exe /language:Csharp /out:c:\hp\DataService.cs /uri:http://localhost:54944/WcfDataService1.svc/ TestEntities context = new TestEntities(new Uri("http://localhost:54944/WcfDataService1.svc/")); List <Student> students = context.Students.ToList(); }
public ActionResult List() { TestEntities db = new TestEntities(); IEnumerable <RequestData> list = db.RequestDatas.Where(x => x.Dactive == true).OrderByDescending(x => x.ReqDate).ToList(); return(View(list)); }
public List <Course> GetAll() { using (var context = new TestEntities()) { var courses = context.Courses.ToList(); return(courses); } }
// GET: Request public ActionResult Index() { TestEntities db = new TestEntities(); ViewBag.B_id = new SelectList(db.Bloodgroups, "B_id", "BloodName"); ViewBag.DistrictId = new SelectList(db.Districts, "DistrictId", "DistrictName"); return(View()); }
public Person GetById(int id) { using (var context = new TestEntities()) { var people = context.People.Include(p => p.Clients).FirstOrDefault(p => p.Id == id); return(people); } }
public List <Person> GetAll() { using (var context = new TestEntities()) { var people = context.People.ToList(); return(people); } }
public List <Student> GetAll() { using (var context = new TestEntities()) { var students = context.Students.ToList(); return(students); } }
public User GetUserById(int id) { using (var context = new TestEntities()) { var user = context.Users.FirstOrDefault(u => u.Id == id); return(user); } }
public Student GetById(int id) { using (var context = new TestEntities()) { var stu = context.Students.Include(p => p.Courses).FirstOrDefault(p => p.id == id); return(stu); } }
public Course GetById(int id) { using (var context = new TestEntities()) { var course = context.Courses.Include(p => p.Students).FirstOrDefault(p => p.id == id); return(course); } }
public void CRUD_Test() { var repositoryContext = new RepositoryContext(); Account testAccount = TestEntities.GetTestAccount( 1, Guid.Parse("F341B4FB-4CC3-4FDB-B7CF-8DCD45365341"), "AccAddr"); try { // delete test account TestDataCleaner.DeleteTestAccount(repositoryContext, testAccount.AccountId); // create account repositoryContext.AccountRepository.Upsert(testAccount); // create AccountAddress expectedAccountAddress = TestEntities.GetTestAccountAddress(1, testAccount.AccountId); repositoryContext.AccountAddressRepository.Upsert(expectedAccountAddress); // read AccountAddress actualAccountAddress = repositoryContext.AccountAddressRepository.Get(expectedAccountAddress.AccountId); Assert.NotNull(actualAccountAddress); Assert.True(EntityComparer.AreAccountAddressEqual(expectedAccountAddress, actualAccountAddress)); // update AccountAddress expectedAccountAddressNew = TestEntities.GetTestAccountAddress( 2, expectedAccountAddress.AccountId); repositoryContext.AccountAddressRepository.Upsert(expectedAccountAddressNew); Assert.AreEqual(expectedAccountAddress.AccountId, expectedAccountAddressNew.AccountId); AccountAddress actualAccountAddressNew = repositoryContext.AccountAddressRepository.Get(expectedAccountAddressNew.AccountId); Assert.NotNull(actualAccountAddressNew); Assert.True( EntityComparer.AreAccountAddressEqual(expectedAccountAddressNew, actualAccountAddressNew)); // delete repositoryContext.AccountRepository.Delete(expectedAccountAddress.AccountId); // read by id actualAccountAddress = repositoryContext.AccountAddressRepository.Get(expectedAccountAddress.AccountId); Assert.Null(actualAccountAddress); } finally { // delete test account TestDataCleaner.DeleteTestAccount(repositoryContext, testAccount.AccountId); repositoryContext.Dispose(); } }
public Person AddOrUpdate(Person person) { using (var context = new TestEntities()) { context.People.AddOrUpdate(person); int count = context.SaveChanges(); return(person); } }
//add many2many:make sure the navigation attribute empty public Student Add(Student student) { using (var context = new TestEntities()) { context.Students.AddOrUpdate(student); int count = context.SaveChanges(); return(student); } }
public async Task <List <Menu> > GetAll() { using (var context = new TestEntities()) { var menu = await context.Menus.OrderBy(x => x.type).ToListAsync(); return(menu); } }
public static void ClassInit(TestContext context) { AppDomain.CurrentDomain.SetData("DataDirectory", context.TestDeploymentDir); // warm-up, to get more realistic test run times. using (var ctx = new TestEntities()) { ctx.Orders.ToList(); } }
public void TestSetup() { _context = new TestEntities(); if (_context.Database.Exists()) { _context.Database.Delete(); } _context.Database.Create(); }
public Client AddOrUpdate(Client client) { using (var context = new TestEntities()) { context.Clients.AddOrUpdate(client); int count = context.SaveChanges(); return(client); } }
public void UpsertAccount_ThrowsValidationExceptionIfAccountNameIsInvalid(string invalidString) { using (var repositoryContext = new RepositoryContext()) { Account account = TestEntities.GetTestAccount(1, Guid.Empty, TestValues.ValidString); account.AccountName = invalidString; Assert.ThrowsException <ValidationException>(() => repositoryContext.AccountRepository.Upsert(account)); } }
public TestRepository(IUnitOfWork unitOfWork) : base(unitOfWork as VoltEntities) { if (unitOfWork == null) { throw new ArgumentNullException("unitOfWork"); } _context = unitOfWork as TestEntities; }
public Course AddOrUpdate(Course course) { using (var context = new TestEntities()) { context.Courses.AddOrUpdate(course); int count = context.SaveChanges(); return(course); } }
public void Map_A_Product() { IEnumerable<IDto> dtos; using (var db = new TestEntities()) { var list = db.Set<PRODUCTO>().Take(100).ToList().ConvertListToDto<ProductDTO>(); dtos = list.ToList(); } Assert.Greater(dtos.Count(), 0); }
private void DeleteBut_Click(object sender, RoutedEventArgs e) { using (var entity = new TestEntities()) { var a = entity.prowadzacy.Where(x => x.id_prow == _teacher.id_prow).FirstOrDefault(); entity.prowadzacy.Remove(a); entity.SaveChanges(); _page.UpdateTeacherView(); } }
public string Delete(int id) { using (var db = new TestEntities()) { var al = db.Alumnoes.Where(a => a.id == id).FirstOrDefault(); db.Alumnoes.Remove(al); db.SaveChanges(); return("Deleted successfully"); } }
public async Task <Menu> AddOrUpdate(Menu menu) { using (var context = new TestEntities()) { context.Menus.AddOrUpdate(menu); int count = await context.SaveChangesAsync(); return(menu); } }
private void btnLink_Click(object sender, EventArgs e) { object[] items = chklistbox.CheckedItems.OfType <object>().ToArray(); var target = "Lot"; if (chklistbox.CheckedItems.Count == 0) { MessageBox.Show("You didn't check anything dope. Try again"); } else { target += txtBaseId.Text.Substring(11, 2); bool has = items.Contains(target); if (has == true) { TestEntities db = new TestEntities(); Link link = new Link(); link.BaseID = txtBaseId.Text.Substring(0, 8); string lots = ""; for (int o = 0; o < items.Length; o++) { if (lots == "") { if (items[o].ToString().Length == 4) { lots += items[o].ToString().Substring(3, 1); } else { lots += items[o].ToString().Substring(3, 2); } } else { if (items[o].ToString().Length == 4) { lots += "," + items[o].ToString().Substring(3, 1); } else { lots += "," + items[o].ToString().Substring(3, 2); } } link.LinkedLots = lots; } db.Links.Add(link); db.SaveChanges(); MessageBox.Show("Lots " + lots + " Successfully Linked. Keep up the Good Work!"); } else { MessageBox.Show("Dude. The lot you selected isn't in the link list you made. TRY AGAIN"); } } }
/// <summary> /// 测试 AUTO_INCREMENT 在系统中,是否会影响 EF 的运作。 /// </summary> public static void DoTest() { using (TestEntities context = new TestEntities()) { Console.WriteLine(); Console.WriteLine("测试 AUTO_INCREMENT Start!"); Console.WriteLine("首先测试 执行插入处理!"); try { test_auto_increment_tab test1 = new test_auto_increment_tab() { value = "测试" }; context.test_auto_increment_tab.AddObject(test1); context.SaveChanges(); Console.WriteLine("执行插入成功!"); Console.WriteLine("数据库那里产生了自增的 AUTO_INCREMENT 数值, 同时更新到当前这个字段上."); Console.WriteLine("test1 的 id = {0}", test1.id); Console.WriteLine("尝试再检索."); var query = from data in context.test_auto_increment_tab where data.value == "测试" select data; foreach (test_auto_increment_tab t in query) { Console.WriteLine("id = {0}; value = {1} ", t.id, t.value); context.test_auto_increment_tab.DeleteObject(t); } context.SaveChanges(); Console.WriteLine("执行删除成功!"); } catch (Exception ex) { Console.WriteLine("执行失败!"); Console.WriteLine(ex.Message); } Console.WriteLine("测试 AUTO_INCREMENT Finish!"); Console.WriteLine(); } }
public TeacherTypeComboViewModel() { Type = new List <Model.typy_prowadzacych>(); using (var entity = new TestEntities()) { foreach (var item in entity.typy_prowadzacych) { Type.Add(item); } } }
private void txtBaseId_TextChanged(object sender, EventArgs e) { TestEntities test = new TestEntities(); var acs = from a in test.ActiveJobs select a.BaseID; AutoCompleteStringCollection sn = new AutoCompleteStringCollection(); sn.AddRange(acs.ToArray()); txtBaseId.AutoCompleteMode = AutoCompleteMode.Suggest; txtBaseId.AutoCompleteSource = AutoCompleteSource.CustomSource; txtBaseId.AutoCompleteCustomSource = sn; }
public static void GetCustomerById(int customerId) { TestEntities database = new TestEntities(); Customer result = database.Customers.SingleOrDefault(cust => cust.CustomerId == customerId); //Expected a value. Null here indicates no record with this ID. Assert.NotNull(result); //Uh oh! Assert.Equal(customerId, result.CustomerId); }
public static bool Delete(int id) { try { TestEntities context = new TestEntities(); context.tblStudents.DeleteObject(context.tblStudents.FirstOrDefault(student => student.ID == id)); return true; } catch (Exception ex) { return false; } }
public ActionResult Delete(Int32 IdPersona) { TestEntities context = new TestEntities(); try { Personas p = context.Personas.First(i => i.Id == IdPersona); context.Personas.Remove(p); context.SaveChanges(); return RedirectToAction("Index"); }catch(Exception) { //ModelState.AddModelError("", e.Message); return RedirectToAction("Error"); } }
public ActionResult Captura(Int32 IdPersona) { TestPerson.Models.Person PersonEdit = null; if(IdPersona != 0) { TestEntities context = new TestEntities(); var person = from r in context.Personas where r.Id == IdPersona select r; foreach (Personas p in person) { PersonEdit = new Models.Person { Id = p.Id, Nombre = p.Nombre, FechaNac = p.FechaNacimiento.ToShortDateString(), Pic = p.Foto }; } return View(PersonEdit); } return View(); }
public static Models.DomainModel.Student Get(int studentID) { TestEntities context = new TestEntities(); var student = context.tblStudents.FirstOrDefault(s => s.ID == studentID); return new Models.DomainModel.Student() { ID = student.ID, Name = student.tblPerson.Name, FatherName = student.tblPerson.FatherName, MotherName = student.tblPerson.MotherName, Age = student.tblPerson.Age, Gender = student.tblPerson.Gender.ToString(), CreatedBy = student.CreatedBy, CreatedDate = student.CreatedDate, AddressDetails = new Models.DomainModel.Address() { HouseNo = student.tblAddress.HouseNo } }; }
public static int Add(Models.DomainModel.Student student) { using (TestEntities context = new TestEntities()) { tblAddress objAddress = new tblAddress() { HouseNo = student.AddressDetails.HouseNo, Locality = student.AddressDetails.Locality, City = student.AddressDetails.City, District = student.AddressDetails.District, State = student.AddressDetails.State, CreatedDate = DateTime.Now, CreatedBy = "admin" }; tblPerson objPerson = new tblPerson() { Name = student.Name, FatherName = student.FatherName, MotherName = student.MotherName, Age = student.Age, Gender = 1, CreatedDate = DateTime.Now, CreatedBy = "admin" }; context.tblAddresses.AddObject(objAddress); context.tblPersons.AddObject(objPerson); tblStudent objStudent = new tblStudent() { PersonID = objPerson.ID, AddressID = objAddress.ID, CreatedDate = DateTime.Now, CreatedBy = "admin" }; context.tblStudents.AddObject(objStudent); context.SaveChanges(); return objStudent.ID; } }
public ActionResult Captura(TestPerson.Models.Person P, HttpPostedFileBase Foto) { try { TestEntities context = new TestEntities(); Byte[] bytes = null; if (Foto != null) { Stream str = Foto.InputStream; BinaryReader br = new BinaryReader(str); bytes = br.ReadBytes((Int32)str.Length); } if (P.Id != 0) { var DatoOriginal = context.Personas.Find(P.Id); DatoOriginal.Nombre = P.Nombre; DatoOriginal.FechaNacimiento = Convert.ToDateTime(P.FechaNac); DatoOriginal.Foto = bytes; context.SaveChanges(); } else { Personas person = new Personas { Id = P.Id, Nombre = P.Nombre, FechaNacimiento = Convert.ToDateTime(P.FechaNac), Foto = bytes }; context.Personas.Add(person); context.SaveChanges(); //int id = person.Id; } return RedirectToAction("Index"); } catch (Exception e) { Response.Write(e.Message); } return View(); }
public void Setup() { _testEntities = new TestEntities(); _parent = new FooParent(); _child = new FooChild(); }
public static void Update(Models.DomainModel.Student student) { using (TestEntities context = new TestEntities()) { var objStudent = context.tblStudents.FirstOrDefault(s => s.ID == student.ID); objStudent.tblPerson.Name = student.Name; objStudent.tblPerson.FatherName = student.FatherName; objStudent.tblPerson.MotherName = student.MotherName; objStudent.tblPerson.Age = student.Age; objStudent.tblPerson.Gender = 1; //objStudent.tblAddress.HouseNo = student.AddressDetails.HouseNo; context.SaveChanges(); } }
public ActionResult DeletePhone(Int32 Id) { TestEntities Context = new TestEntities(); TestPerson.Telefonos T = Context.Telefonos.First(i => i.Id == Id); Context.Telefonos.Remove(T); Context.SaveChanges(); return RedirectToAction("Index"); }
public String Nombre(Int32 IdPersona) { TestEntities Context = new TestEntities(); var result = from p in Context.Personas where p.Id == IdPersona select p; return result.ElementAt(0).Nombre; }
public ActionResult Index() { List<TestPerson.Models.Person> ListaPersonas = new List<Models.Person>(); using (TestEntities context = new TestEntities()) { var person = (from r in context.Personas select r); foreach (Personas record in person) { Models.Person p = new Models.Person { Id= record.Id, Nombre = record.Nombre, FechaNac = record.FechaNacimiento.ToShortDateString(), Pic = (Byte[]) record.Foto }; ListaPersonas.Add(p); } } return View("Index", ListaPersonas); }
public IEnumerable GetPhones(Int32 IdPersona) { TestEntities Context = new TestEntities(); var result = from p in Context.Telefonos where p.IdPersona == IdPersona select p; return result.ToList(); }
public ActionResult EditPhone(Int32 IdPhone, String txtPhone, Int32 IdPerson) { TestEntities Context = new TestEntities(); if (IdPhone == 0) { TestPerson.Telefonos T = new TestPerson.Telefonos { IdPersona = IdPerson, Telefono = txtPhone }; Context.Telefonos.Add(T); Context.SaveChanges(); } else { var DatoOriginal = Context.Telefonos.Find(IdPhone); DatoOriginal.Telefono = txtPhone; Context.SaveChanges(); } return RedirectToAction("Index"); }
public static List<Models.DomainModel.Student> GetAll() { TestEntities context = new TestEntities(); return (from student in context.tblStudents select student).Select(student => new Models.DomainModel.Student() { ID = student.ID, Name = student.tblPerson.Name, FatherName = student.tblPerson.FatherName, MotherName = student.tblPerson.MotherName, Age = student.tblPerson.Age, //Gender = Convert.ToString(student.tblPerson.Gender), CreatedBy = student.CreatedBy, CreatedDate = student.CreatedDate, AddressDetails = new Models.DomainModel.Address() { HouseNo = student.tblAddress.HouseNo } }).ToList<Models.DomainModel.Student>(); }
public TestUnitOfWork(TestEntities entities) : base(entities) { }