前面一节,我们学习了怎样处理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) { ... }
}

参考文章

 


 

相关文章:

  • 2021-07-07
  • 2021-12-15
  • 2022-12-23
  • 2021-04-30
  • 2021-04-10
  • 2021-11-08
  • 2021-05-19
  • 2022-02-04
猜你喜欢
  • 2022-02-08
  • 2021-12-14
  • 2021-10-25
  • 2021-10-02
  • 2022-12-23
  • 2021-06-13
相关资源
相似解决方案