WCF RIA Service中 POCO实体含有复杂类型的增删改注意点

前面一节,我们学习了怎样处理POCO实体含有复杂类型,但是对于增删改会出错,我们还要继续处理,要添加[Composition]特殊属性标识符。 

// "Master" domain entity class.

public class Parameter {
[Key]
public long Id { get; set; }

public string Name { get; set; }

[Include]
[Composition]
[Association(
"Parameter_Options", "Id", "ParameterId")]
public List<Option> Options { get; set; }
}

// "Details" domain entity class.

public class Option {
[Key]
public long Id { get; set; }

public long ParameterId { get; set; }

public string Name { get; set; }
}

我们还要添加相应的增删改方法,如下,而且我们还要添加AddOption, UpdateOption and DeleteOption方法,其方法可以为空。修改如下:

[EnableClientAccess]
public class ParametersDomainService : DomainService
{
[Query]
public IEnumerable<Parameter> GetParameters() { ... }
[Insert]
public void AddParameter(Parameter parameterWithOptions) { ... }
[Update]
public void UpdateParameter(Parameter parameterWithOptions) { ... }
[Delete]
public void DeleteParameter(Parameter parameterWithOptions) { ... }

[Insert]
public void AddOption(Option option) { ... }
[Update]
public void UpdateOption(Option option) { ... }
[Delete]
public void DeleteOption(Option option) { ... }
}

参考文章

 


 

posted @ 2011-09-20 15:23  焦涛  阅读(379)  评论(0编辑  收藏  举报