这个协会ORM怎么样? [英] How about this association ORM

查看:70
本文介绍了这个协会ORM怎么样?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

public class Employee
{
    public byte ID { get; set; }
    public string Name { get; set; }
}
public class Task 
{
    public int ID { get; set; }
    public string Description { get; set; }


    private  List<Employee> employeeTask ;
    public  List<Employee> EmployeeTask
    {
            get
            {
                if (employeeTask == null)
                {
                    employeeTask = //Any Source changeable ;
                }
                return employeeTask; 
            }
    }
}
class Program
{
    void main()
    {
         List<Task> ListTask = //fill with groub of Tasks;
                               /*When Call 
                               property EmployeeTask in every Object in list (ListTask), 
                               the property(EmployeeTask) in all Object 
                               have the Same content (have last content element)*/
     }
}



如何在ListTask中创建每个对象拥有自己的内容(属性EmployeeTask)??


How i can make every object in ListTask have Content of its own( property EmployeeTask )??

推荐答案

只需完成类任务。将 getter 添加到属性 EmployeeTask 或添加一个构造函数,接受类型 List< Employee> 初始化此属性的值。



但是,即使现在代码不完整,整个设计也值得怀疑。您需要将属性封装在任务列表中。永远不要离开字段 employeeTask 未初始化,在声明点用空列表初始化它。 (可选)为列表提供列表界面,而不暴露列表本身。



-SA
Just complete the class Task. Either add the getter to the property EmployeeTask or add a constructor accepting the value of the type List<Employee> to initialize the value of this property.

However, the whole design is questionable even now when the code is incomplete. You need to property encapsulate the list of tasks. Never leave the field employeeTask uninitialized, initialize it at the point of declaration with an empty list. Optionally, provide a list interface for the list without exposing the list itself.

—SA


这篇关于这个协会ORM怎么样?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆