.NET 學習

.NET 學習生活感想... 万事成蹉跎..... 贵在坚持 及时整理自己做过和学过的东西

博客园 首页 新随笔 联系 订阅 管理

DC: 一对多关系
In the first post of the series devoted to our new domain component (DC) technology, I tried to show an interface-defined entity in a UI.

在第一篇博客专门讨论我们新的领域构件技术,我试着在界面显示一个接口定义实体。

I used some IPerson component as an example:
我用一些Iperson构件作为例子:

 

view plain | print | copy to clipboard

1

public enum Gender { Unknown, Male, Female }  

2

 

3

    public interface IPerson {  

4

        string FirstName { getset; }  

5

        string MiddleName { getset; }  

6

        string LastName { getset; }  

7

        string FullName { get; }  

8

        DateTime Birthday { getset; }  

9

        Gender Gender { getset; }  

10

    }  

11

    [DomainLogic(typeof(IPerson))]  

12

    public class PersonLogic {  

13

        public static string Get_FullName(IPerson self) {  

14

            return self.FirstName + " " + self.LastName;  

15

        }  

16

    } 

IPerson is a library interface that will be used as an entity rarely. In a real-world application, another entity is expected. For instance, it may be a Developer, the entity that implements the IPerson interface, in addition to other interfaces. Assume the Developer contains Notes. So, we add the INote and IItemWithNotes library interfaces:
Iperson
是一个库接口,很少最为实体用。在现实世界的应用程序,另一实体是被预期的。例如,他可能是一个开发者,实体实现Iperson接口,除了其他接口。认为开发包括备注。因此,我们添加InoteIitemWithNote库接口:

 

view plain | print | copy to clipboard

1

public interface IItemWithNotes {  

2

        IList<INote> Notes { get; }  

3

    }  

4

 

5

    public interface INote {  

6

        string Text { getset; }  

7

        IItemWithNotes Owner { getset; }  

8

    } 

 

Combining these two interfaces, we get the IDeveloper interface:

结合这两个接口,我们得到了Ideveloper接口:

 

view plain | print | copy to clipboard

1

public interface IDeveloper : IPerson, IItemWithNotes{   

2

    } 

I change the entity registration code, which I showed in the previous post, to the following:
我更改实体注册代码,我发布在以前的帖子上,如下:

 

view plain | print | copy to clipboard

1

    public override void Setup(XafApplication application) {  

2

            XafTypesInfo.Instance.AddEntityToGenerate("Developer"typeof(IDeveloper));  

3

            XafTypesInfo.Instance.GenerateEntities();  

4

            base.Setup(application);  

5

        } 

If I run my application now, it won't work. The problem is that I should map the INote interface to a real entity. Here, I have a design challenge: should XAF generate other entities for the Developer entity, or should it require that all Developer-related entities are registered manually? Currently, I think it is better to make a developer responsible for registering entities. First, it will give him direct control on what happens in the physical database. Second, our automatic logic can be wrong. So, I change the entity registration code again:
如果我现在运行我的应用程序,它不能运行。问题是,·映射一个真实的实体接口。这里,我有了设计挑战:XAF为开发者实体生成其他实体,或者,现在应当需要手动注册所有开发者相关实体,我认为最好的方法是让开发者自己负责注册实体。首先,会给它直接控制在数据库操作。其次,我们的自动逻辑可能是错的。因此,我再次改变实体注册代码:

 

view plain | print | copy to clipboard

1

    public override void Setup(XafApplication application) {  

2

            XafTypesInfo.Instance.AddEntityToGenerate("Developer"typeof(IDeveloper));  

3

            XafTypesInfo.Instance.AddEntityToGenerate("Note"typeof(INote));  

4

            XafTypesInfo.Instance.GenerateEntities();  

5

            base.Setup(application);  

6

        } 

After I made these changes, my application works:
更改之后,应用程序可以运行:

Note that the FullName property is calculated properly. Remember that we declared this property with a getter only. However, we implemented the PersonLogic class that contains the Get_FullName method. When the XpoBuilder generated the implementation of the Developer object, it uses the Get_FullName method to generate the FullName property.
注意,FullName属性是计算属性。记得,我们只用一个getter定义这个属性。然而,我们实现了包含Get_FullName方法的类。当XpoBuilder生成开发者对象的实现时,它用了Get_FullName方法生成FullName属性。

As you can see in the screenshot above, the "Link" and "Unlink" Actions are available (they are circled). This means that the system thinks that a Note object can be created independently. I need a way to tell the XpoBuilder that the
IItemWithNotes.Notes is an aggregated collection. I want to be able to write this:
正如你在上面截图中看到的,“Link”和“Unlink”按钮可用。这就意味系统认为独立创建一个Note对象.我需要一个方法告诉XpoiBuilderIItemWithNotes.Notes是一个聚集集合。我希望是这样写:

 

view plain | print | copy to clipboard

1

public interface IItemWithNotes {  

2

        [Aggregated]  

3

        IList<INote> Notes { get; }  

4

    } 

I still can't do that. So, I've written a test that shows what I need, and now I’m waiting for the Xpo team. I'll focus on other problems with associations. Stay tuned.
我仍不能做到这一点。因此,我写一个测试显示我需求什么,现在,我等待XPO团队。我将关注与关联相关的问题。敬请关注。

posted on 2011-01-20 15:15  Tonyyang  阅读(894)  评论(0编辑  收藏  举报
欢迎转载,转载请注明出处:http://www.cnblogs.com/Tonyyang/