我正在创建一种新的方式来做我的项目中的事情,我在某些时候需要一些帮助。我的解决方案中有 3 个项目:
业务、提供商和模型。
MODEL 项目是我拥有的类,就像数据库中的表一样:例如:
public class Person
property Id as integert?
property Name as string
property CPF as string
end class
PROVIDER 项目是与数据库进行通信的项目:
public class PersonProvider
public function ListPerson(filter as model.person) as list(of model.person)
public sub insertPerson(byRef person as model.peson)
public sub updatePerson(byRef person as model.peson)
public sub deletePerson(byRef person as model.peson)
end class
最后,我有 BUSINESS 项目,即向网站公开 CRUD 方法的项目(网站不能访问 PROVIDER,因为我们在 BUSINESS 中有业务逻辑)
public class PersonBusiness
public function ListPerson(filter as model.person) as list(of model.person)
return (new provider.PersonProvider).listPerson(filter)
end public
public sub InsertPerson(byRef person as model.person)
dim provider as new provider.PersonProvider()
provider.insertPerson(person)
end public
...
end class
但是,当我需要这样的内部连接时,我遇到了一个问题:
表 CUSTOMER 有一个 id_person,所以在 model.Customer 我有一个属性 IdPerson 作为整数?
但我想拥有model.Person拥有的属性Name和CPF,model.Customer中的只读属性,所以我做了:
Property IdPerson As Integer?
Private _person As Pessoa
Private ReadOnly Property Person As model.Person
Get
If IsNothing(_person) Then
_person = New provider.PersonProvider.ListPerson(new model.Person with {.Id = Me.IdPerson})
End If
Return _person
End Get
End Property
ReadOnly Property Name As String
Get
Return Me.Person.Name
End Get
End Property
ReadOnly Property CPF As String
Get
Return Me.Pessoa.CPF
End Get
End Property
问题来了……我发现我没有像这样的参考:
网站参考模型和业务
提供者参考模型
业务参考模型和提供者
但是要执行只读属性,模型需要引用提供者,这会导致循环引用..visual studio 不允许我这样做...
知道怎么做吗?
对不起,我的帖子变得这么长,我只是想把事情说清楚。