public Shippers Get(int id) { SqlDataReader reader = helper.GetEntity($"Select * From Shippers Where ShipperID={id}"); Shippers shippers = new Shippers(); while (reader.Read()) { shippers.ShipperID = Convert.ToInt32(reader[nameof(shippers.ShipperID)]); shippers.CompanyName = reader[nameof(shippers.CompanyName)].ToString(); shippers.Phone = reader[nameof(shippers.Phone)].ToString(); } return(shippers); }
public T Get(int id) { Type type = typeof(T); string GetEntity = $"select * from {type.Name} where {type.GetProperties()[0].Name}={id}"; SqlDataReader reader = db.GetEntity(GetEntity); //T entity = new T(); T typeCreate = (T)Activator.CreateInstance(type); while (reader.Read()) { foreach (var item in type.GetProperties()) { item.SetValue(typeCreate, reader[item.Name]); } } return(typeCreate); }