private void FindByid(object obj) { string id = InputId; if (id == null || (id == "")) { ContainersById = materialDB.GetAll <Container>(); MaterialsById = materialDB.GetAll <Material>(); } else { // MaterialsById = materialDB.GetById<Material>(id); //当输入值不为空时,查询第一张表container,如果查询到的数据不为空,往下执行 if (materialDB.GetById <Container>(id) != null) { ContainersById = materialDB.GetById <Container>(id); //获取查询数据的material_id var container = ContainersById.FirstOrDefault(); var containerId = container.id; MaterialsById = materialDB.GetByid <Material>(containerId); } //如果在container表中查询不到数据,就在第二张表material中查询 else { MaterialsById = materialDB.GetByMaterialId <Material>(id); var material = MaterialsById.FirstOrDefault(); var containerid = material.containerId; ContainersById = materialDB.GetByMaterialid <Container>(containerid); } } }
public void TestMethod1() { MaterialDB materialDB = new MaterialDB(); string id = "3"; Material material = materialDB.GetById <Material>(id); Console.WriteLine(material); }