业务实体层次结构OO问题 [英] Business Entity Hierarchy OO question

查看:64
本文介绍了业务实体层次结构OO问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在努力解决这个问题。


我有一个商业实体员工,其中附有公司实体




Ex:


公共课Compay {// blah}


公共班职员< br $>
{

private Company _company;


public Company Company {// get / set}

}


我正在寻找一种获取公司参考数据的好方法。

现在,公司信息在需要时得到,所以公司有一个单独的

查询。如果您有一个名单
的员工,这会出现问题。您可以通过一个查询获得10名员工,但随后又有10个查询,每个公司一个查询。如果你在Employee对象上有更多的

引用而不仅仅是公司,并且公司

上有引用对象,那么这就相加了。


我知道解决这个问题的一种方法是使用构建器。因此,您获得了员工的
列表,将其传递给构建者,构建者会查询

获取这些员工的公司,然后循环并匹配

他们了。我发现这不能很好地工作,这可能是我实现它的方式




当.NET 3.5中的LINQ发布时,这应该可以解决这个问题,但是

还没有一段时间了,我仍然想知道一个好的

的方法来做到这一点所有语言,不仅仅是.NET 3.5。


有什么建议吗?


谢谢。

解决方案

我有一个例子


客户。

客户有订单


请参阅
http://sholliday.spaces.live。 com / blog /

6/5/2006

自定义对象和分层开发II // 2.0

我使用IDataReader .NextResult()调用。


有2个查询。我认为这对于你正在寻找的

来说是合适的粒度。


" Narshe" < na **** @ gmail.com写信息

news:11 ********************** @ 8g2000cwh.googlegrou ps.com ...


我一直在努力解决这个问题。


我有生意实体雇员附有公司实体




Ex:


公共类Compay {/ / blah}


公共班级员工

{

private Company _company;


public Company Company {// get / set}

}


我正在寻找一种获取公司参考数据的好方法。

现在,公司信息在需要时获得,因此该公司有一个单独的

查询。如果您有一个名单
的员工,这会出现问题。您可以通过一个查询获得10名员工,但随后又有10个查询,每个公司一个查询。如果你在Employee对象上有更多的

引用而不仅仅是公司,并且公司

上有引用对象,那么这就相加了。


我知道解决这个问题的一种方法是使用构建器。因此,您获得了员工的
列表,将其传递给构建者,构建者会查询

获取这些员工的公司,然后循环并匹配

他们了。我发现这不能很好地工作,这可能是我实现它的方式




当.NET 3.5中的LINQ发布时,这应该可以解决这个问题,但是

还没有一段时间了,我仍然想知道一个好的

的方法来做到这一点所有语言,不仅仅是.NET 3.5。


有什么建议吗?


谢谢。



" Narshe" < na **** @ gmail.com写信息

news:11 ********************** @ 8g2000cwh.googlegrou ps.com ...


我一直在努力解决这个问题。


我有生意实体雇员附有公司实体




Ex:


公共类Compay {/ / blah}


公共班级员工

{

private Company _company;


public Company Company {// get / set}

}


我正在寻找一种获取公司参考数据的好方法。

现在,公司信息在需要时获得,因此该公司有一个单独的

查询。如果您有一个名单
的员工,这会出现问题。您可以通过一个查询获得10名员工,但随后又有10个查询,每个公司一个查询。如果你在Employee对象上有更多的

引用,而不仅仅是公司,并且如果公司

上有参考对象,这就相加了。



您可以对注册表使用延迟加载。随着延迟加载,直到你实际使用子对象,Employee对象不会做任何事情。
任何东西。当您确实要求公司时,您会询问注册表。如果

注册表已经加载了公司,那么它返回引用,如果它没有b $ b那么它构建它然后返回引用。


一些代码可以给你这个想法


class Employee

{

public Company Company {

获得{

返回Registry.CompanyByID(companyID)

类注册表{

public static CompanyByID(string companyID){

if(companyList.ContainsKey(companyID))

返回comapnyList [companyID]

else {

公司公司= Builder.BuildCompany(companyID);

companyList.Add(companyID,company);

返回公司;


>

我知道解决这个问题的一种方法是使用构建器。因此,您获得了员工的
列表,将其传递给构建者,构建者会查询

获取这些员工的公司,然后循环并匹配

他们了。我发现这不能很好地工作,这可能是我实现它的方式。



一种更简单的方法是一次构建完整的公司列表然后

将其用作查找表。来自员工对象的密钥。如果你有相当静态的
对象,那么当软件启动时你可以更容易地构建它们,然后将你的属性删除,然后就像

public Company Company {

get {

return CompanyList [this.companyKey];


> ;

当.NET 3.5中的LINQ发布时,这应该可以解决问题,但是

已经有一段时间没有了,我仍然想知道一个好的

的方式可以用于所有语言,而不仅仅是.NET 3.5。



还有其他ORM产品已经上市。


PS


>

有什么建议吗?


谢谢。



您可以对注册表使用延迟加载。延迟加载,直到你


实际使用子对象,Employee对象不会做任何事情。当您确实要求公司时,您会询问注册表。如果

注册表已经加载了公司,那么它返回引用,如果它没有b $ b那么它构建它然后返回引用。



如何使注册表无效?当检索到数据时,它很可能会很快被更改,所以我需要一种方式

来使注册表无效。我知道在SQL 2005中你可以做行级别

缓存失效,但我们在2000年这里。


一个更简单的方法要一次构建完整的公司列表然后

将其用作查找表。来自员工对象的密钥。如果你有相当静态的
对象,那么当软件启动时你可以更容易地构建它们,然后将你的属性删除,然后就像

public Company Company {

get {

return CompanyList [this.companyKey];



我也考虑过这个问题,但是在某些时候列表需要

无效。


还有其他ORM产品可用。



我将不得不调查此事。


-Josh


I''ve been struggling with this for a while.

I have a business entity Employee that has a Company entity attached
to it.

Ex:

public class Compay{ // blah }

public class Employee
{
private Company _company;

public Company Company{ // get/set }
}

I''m looking for a good way to get the data for the Company reference.
Right now, the company info is got when needed, so there is a separate
query for the company. This presents a problem when you have a list
of Employees. You get 10 employees with one query, but then there are
10 more queries, one for each Company. This adds up if you have more
references on the Employee object than just Company, and if Company
has reference objects on it.

I know one way to solve this is to use a builder. So, you get your
list of Employees, pass it to a builder, the builder does a query to
get the Companies for those Employees, and you loop through and match
them up. I''ve found this to not work too well, which could be the way
I implemented it.

When LINQ in .NET 3.5 is released, this should solve the issue, but
that''s not for a while yet and I still would like to know of a good
way to do it that will work for all languages, not just .NET 3.5.

Any suggestions?

Thanks.

解决方案

I have an example

Customers.
Customers have Orders

See
http://sholliday.spaces.live.com/blog/
6/5/2006
Custom Objects and Tiered Development II // 2.0
I use the IDataReader.NextResult() call.

There are 2 queries. Which I believe is the appropriate granularity for
what you''re looking for.


"Narshe" <na****@gmail.comwrote in message
news:11**********************@8g2000cwh.googlegrou ps.com...

I''ve been struggling with this for a while.

I have a business entity Employee that has a Company entity attached
to it.

Ex:

public class Compay{ // blah }

public class Employee
{
private Company _company;

public Company Company{ // get/set }
}

I''m looking for a good way to get the data for the Company reference.
Right now, the company info is got when needed, so there is a separate
query for the company. This presents a problem when you have a list
of Employees. You get 10 employees with one query, but then there are
10 more queries, one for each Company. This adds up if you have more
references on the Employee object than just Company, and if Company
has reference objects on it.

I know one way to solve this is to use a builder. So, you get your
list of Employees, pass it to a builder, the builder does a query to
get the Companies for those Employees, and you loop through and match
them up. I''ve found this to not work too well, which could be the way
I implemented it.

When LINQ in .NET 3.5 is released, this should solve the issue, but
that''s not for a while yet and I still would like to know of a good
way to do it that will work for all languages, not just .NET 3.5.

Any suggestions?

Thanks.



"Narshe" <na****@gmail.comwrote in message
news:11**********************@8g2000cwh.googlegrou ps.com...

I''ve been struggling with this for a while.

I have a business entity Employee that has a Company entity attached
to it.

Ex:

public class Compay{ // blah }

public class Employee
{
private Company _company;

public Company Company{ // get/set }
}

I''m looking for a good way to get the data for the Company reference.
Right now, the company info is got when needed, so there is a separate
query for the company. This presents a problem when you have a list
of Employees. You get 10 employees with one query, but then there are
10 more queries, one for each Company. This adds up if you have more
references on the Employee object than just Company, and if Company
has reference objects on it.

You can use lazy loading with a registry. With lazy loading until you
actually use the child object the Employee object is not going to do
anything. When you do request the Company you ask the registry. If the
registry already has loaded the Company then it returns the reference, if it
has not then it builds it and then returns the reference.

A little bit of code to give you the idea

class Employee
{
public Company Company {
get {
return Registry.CompanyByID(companyID)

class Registry {
public static CompanyByID(string companyID) {
if(companyList.ContainsKey(companyID))
return comapnyList[companyID]
else {
Company company = Builder.BuildCompany(companyID);
companyList.Add(companyID, company);
return company;

>
I know one way to solve this is to use a builder. So, you get your
list of Employees, pass it to a builder, the builder does a query to
get the Companies for those Employees, and you loop through and match
them up. I''ve found this to not work too well, which could be the way
I implemented it.

A easier way would be to build the complete company list at one time then
use this as a lookup "table" by key from the employee objects. If you have
objects that are fairly static then it can be easier to build them all when
the software starts and then delgate your properties to then like
public Company Company {
get{
return CompanyList[this.companyKey];

>
When LINQ in .NET 3.5 is released, this should solve the issue, but
that''s not for a while yet and I still would like to know of a good
way to do it that will work for all languages, not just .NET 3.5.

There are other ORM products already available.

PS

>
Any suggestions?

Thanks.



You can use lazy loading with a registry. With lazy loading until you

actually use the child object the Employee object is not going to do
anything. When you do request the Company you ask the registry. If the
registry already has loaded the Company then it returns the reference, if it
has not then it builds it and then returns the reference.

How is the registry invalidated then? When data is retrieved, it is
more than likely going to be changed soon after, so I would need a way
to invalidate the registry. I know in SQL 2005 you can do row level
cache invalidation, but we''re on 2000 here.

A easier way would be to build the complete company list at one time then
use this as a lookup "table" by key from the employee objects. If you have
objects that are fairly static then it can be easier to build them all when
the software starts and then delgate your properties to then like
public Company Company {
get{
return CompanyList[this.companyKey];

I have thought about this too, but the list would need to be
invalidated at some point.

There are other ORM products already available.

I will have to look into this.

-Josh


这篇关于业务实体层次结构OO问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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