我需要保存/更新单个实体或实体集合。我也为此写了一堂课。在我的示例中,我只使用了两个实体,它们部分和全部保存。但在实际情况下可能会有更多实体:
public class Supplier
{
}
public class Product
{
}
public class Data
{
public Product prod { get; set; }
public Supplier supp { get; set; }
}
//保存实体的对应方法
public static class ProductFactory
{
public static void Save(Product prod)
{
//Save Product table
}
}
public static class SupplierFactory
{
public static void Save(Supplier supp)
{
//Save Supplier table
}
}
//Method to Save All ENTITIES
public static class DataFactory
{
public static void Save(Data data)
{
//Save Data which Consists Product and Supplier
ProductFactory.Save(data.prod);
SupplierFactory.Save(data.supp);
}
}
//Implemention of Save
Product prod = new Product() ;
Supplier supp=new Supplier();
Data data=new Data() ;
//Saving Product individually
ProductFactory.Save(prod);
//Saving Supplier individually
SupplierFactory.Save(supp);
//Saving Data which Consists Supplier and Product
DataFactory.Save(data);
有人可以提出更好的设计吗?在产品/供应商之上可能有更多实体。