public void Insert(ObjectLocation objectLocation) { using (var context = new MyDbContext()) { context.Database.EnsureCreated(); context.ObjectLocation.Add(objectLocation); context.SaveChanges(); } }
public ObjectLocation GetObjectLocationId(int idObject, int idObjectLocation) { ObjectLocation objectRet = new ObjectLocation(); using (var context = new MyDbContext()){ var objects = context.ObjectLocation; var objectsA = objects.Where(p => p.idObjectLocation == idObjectLocation && p.idObject == idObject).ToList(); if (objectsA.Count > 0) { objectRet = objectsA[0]; } } return(objectRet); }
public ObjectLocation GetObjectLocationUltimo(int idObject) { ObjectLocation objectRet = new ObjectLocation(); using (var context = new MyDbContext()){ var objects = context.ObjectLocation; var objectsA = objects.Where(p => p.idObject == idObject).OrderByDescending(o => o.data).ToList(); if (objectsA.Count > 0) { objectRet = objectsA[0]; } } return(objectRet); }