我有一个看起来像这样的对象:
public class MyObject
{
public int UserID {get;set;}
public List<SomeObjects> {get;set;}
public List<SomeOtherObjects {get;set}
public MyObject TheObjectForDB {get;set} //HERE: creating a new object
public MyObject(int TheUserID)
{
this.UserID = TheUserID;
}
public LoadTheObjectFromDatabase()
{
MyQueries TheQueries = new MyQueries();
TheObjectForDB = TheQueries.LoadFromDB(UserID) //HERE: object for DB work
this.List<SomeObjects> = TheObjectForDB.List<SomeObjects>;
this.List<SomeOtherObjects> = TheObjectForDB.List<SomeOtherObjects>;
}
}
数据库查询本质上返回相同的对象类型:
LoadFromDB = from...
select new MyObject(TheUserID){...}
在需要实例化另一个相同类型的对象以填充初始对象的情况下,如何消除这种冗余?
感谢您的建议。