将业务实体填充到UI中 [英] Populating Business Entities into UI

查看:71
本文介绍了将业务实体填充到UI中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

人们,


i被困在我的项目中,我只是不知道如何继续。

它是关于将商业实体放入用户界面(网页)。


首先是一个简单的示例代码实体在我的项目中的样子:


公共类人物:实体

{

string firstName;

string lastName;

public Person(string firstName,string lastName)

{

this.firstName = firstName;

this.lastName = lastName;

}


[EntityMemberAttribute(UINotation =" Firstname",MaxLength = 64)]

public string FirstName

{

get {return this.firstName; }

set {base.MarkDirty(); this.firstName = value; } b / b $

[EntityMemberAttribute(UINotation =" Lastname",MaxLength = 64)]

public string LastName

{

get {return this.lastName; }

set {base.MarkDirty(); this.lastName = value;在UI中我有这个代码来填充该实体:

//获取所有拥有e的人在他们的名字中

EntityCollection people =

SessionFactory.PersonSession.FindByName(" e");


//创建一个新的webtable,设置实体集合

//作为其数据源并绑定

EntityWebTable webTable = new EntityWebTable();

webTable.DataSource =人物;

webTable.DataBind();


瞧!一个aspx页面只显示一个非常好的表,带有标题(

实体中的UINotation标志)和人员本身(名字,

姓氏)


好​​的,很简单,不是吗?


好​​了,到目前为止好了..现在我想隐藏一个字段,让我们说第一个

名称。

所以我想创建一个EntityView。

在EntityView中我可以写这样的东西:


EntityView entityView = new EntityView(typeof(Person));

entityView [" FirstName"]。IsVisible = false;

webTable.DataView = entityView;

....但我不喜欢像这样的强类型代码,因为如果我更改

" FirstName"在Person实体中的属性,不会有任何调试

错误。


另一个解决方案是,为每个实体创建一个自己的视图。所以对于

人物实体,我必须创建一个PersonView ..在那里我可以

说:


personView。 FirstName.IsVisible = false;


...但在这种情况下,我必须为每个实体写一个自己的视图

class如果我添加对于一个实体的一些新属性,我将不得不将它们添加到视图中,这对于每次执行

来说都是非常烦人的。我也想保持风格。在业务逻辑中(

,如符号,表达式,长度);


i也想改变实体本身,所以如果我使用:

" person.FirstName" ..i不会得到一个字符串,我会得到一个对象

和其他一些属性,就像这样。


string firstName = person。 firstName.Value.ToString();

bool isVisible = person.firstName.isVisible;


但我个人也不喜欢这样..因为价值会必须是一个对象,而不是直接一个字符串,这也会导致很多内存中的许多额外对象。

希望有人拥有一些不错的新鲜想法..

谢谢。


史蒂文狼。

hi people,

i got stucked in my project and i just dont know how to continue.
it''s about puting business entities into the UI (web).

first some simple example code how an entity looks like in my project:

public class Person : Entity
{
string firstName;
string lastName;
public Person( string firstName, string lastName )
{
this.firstName = firstName;
this.lastName = lastName;
}

[EntityMemberAttribute( UINotation = "Firstname", MaxLength = 64)]
public string FirstName
{
get { return this.firstName; }
set { base.MarkDirty(); this.firstName = value; }
}

[EntityMemberAttribute( UINotation = "Lastname", MaxLength = 64)]
public string LastName
{
get { return this.lastName ; }
set { base.MarkDirty(); this.lastName = value; }
}
}
in the UI i have this code to populate that entity:
// Get all people who have an "e" in their name
EntityCollection persons =
SessionFactory.PersonSession.FindByName("e");

// Create a new webtable, set the entity collection
// as its datasource and bind
EntityWebTable webTable = new EntityWebTable();
webTable.DataSource = persons;
webTable.DataBind();

voila! an aspx page just shows me a pretty nice table, with captions (
UINotation flag in the entity ) and the persons itself ( firstname,
lastname )

ok, quite simple, isnt?

well, so far ok.. now i want to hide an field, let''s say the first
name.
so i thoguht about creating an EntityView.
in that EntityView i could write something like this:

EntityView entityView = new EntityView( typeof ( Person ));
entityView["FirstName"].IsVisible = false;
webTable.DataView = entityView;
....but i dont like strong typed code like this, because if i change the
"FirstName" property in the Person entity, there wouldn''t be any debug
error.

another solution would be, creating for each entity an own view. so for
the Person Entity, i would have to create a PersonView.. there i could
say:

personView.FirstName.IsVisible = false;

...but in that case, i would have to write for each entity an own view
class and if i add some new properties to an entity, i would have to
add them into the view too, and this would be pretty annoying doing
that each time. i also like to keep the "style" in the business logic (
like the notation, expressions, length );

i thought also about to change the entities itself, so if i use:
"person.FirstName" ..i would''nt get a string, i would get an object
with some other properties, something like this.

string firstName = person.firstName.Value.ToString();
bool isVisible = person.firstName.isVisible;

but personally i dont like that too..since the Value would have to be
an object, instead directly an string and this would also lead to many
many additional objects in memory.
hope somebody have some nice fresh ideas..
thanks.

steven wolf.

推荐答案



< ap **** @ gmx.net>在消息中写道

新闻:11 ********************** @ o13g2000cwo.googlegr oups.com ...

<ap****@gmx.net> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
好吧,到目前为止确定..现在我想隐藏一个字段,让我们说第一个名字。
所以我想创建一个EntityView。在那个EntityView我可以写这样的东西:

EntityView entityView = new EntityView(typeof(Person));
entityView [" FirstName"]。IsVisible = false;
webTable.DataView = entityView;

...但我不喜欢像这样的强类型代码,因为如果我改变了
FirstName Person实体中的属性,不会有任何调试错误。


我没有看到创建EntityView的重点。你已经转向了使数据感知组件可以使用集合的麻烦,所以现在使用数据感知UI组件的强大功能。设置web

表的属性以确定显示哪些列(或字段)。


但是,如果字段名称没有找到错误改变了

是有效的。

i也想改变实体本身,所以如果我使用:
" person.FirstName" ..i不会得到一个字符串,我会得到一个对象
与其他一些属性,像这样。

string firstName = person.firstName.Value.ToString();
bool isVisible = person.firstName.isVisible;

但我个人也不喜欢那样..因为Value必须是一个对象,而不是直接一个字符串,这个还会在内存中导致许多额外的对象。
well, so far ok.. now i want to hide an field, let''s say the first
name.
so i thoguht about creating an EntityView.
in that EntityView i could write something like this:

EntityView entityView = new EntityView( typeof ( Person ));
entityView["FirstName"].IsVisible = false;
webTable.DataView = entityView;
...but i dont like strong typed code like this, because if i change the
"FirstName" property in the Person entity, there wouldn''t be any debug
error.
I don''t see the point in creating an "EntityView". You''ve gone to the
trouble of making the collection usable by data-aware components so now use
the power of the data-aware UI component. Set the properties of the web
table to determine what columns (or fields) get displayed.

However, your concern about not finding errors if the field name is changed
is valid.
i thought also about to change the entities itself, so if i use:
"person.FirstName" ..i would''nt get a string, i would get an object
with some other properties, something like this.

string firstName = person.firstName.Value.ToString();
bool isVisible = person.firstName.isVisible;

but personally i dont like that too..since the Value would have to be
an object, instead directly an string and this would also lead to many
many additional objects in memory.




这是我们采取的方法。它为我们提供了许多优点,而不是简单的b $ b属性值(特别是在对象持久性方面),但仍然没有解决你正在处理的问题。我不认为你想在业务对象本身上设置字段的可见性。这是将

业务对象耦合到UI,并且可能存在一些名称

应该可见的地方以及其他不应该看到的地方。 IMO,业务对象

不应该关心可见性 - 这是UI的工作。



This is the approach we took. It provides many advantages to us over simple
property values (especially in the area of object persistence), but still
doesn''t solve the problem you are tackling. I don''t think you want to set
visibility of a field on the business object itself. That''s coupling the
business object to the UI and there may be some places where firstname
should be visible and others where it should not. IMO, the business object
shouldn''t care anything about visibility - that''s the job of the UI.


我可以轻松地比如说,随着你的设计的发展,你会发现你实现了DataSet,并且EntityTable将是一个DataGrid,但是有一点将是b / b
不同,DataSet由一个庞大的团队,为更广泛的情况提供解决方案。
i can easly say that, as you evolve your design, you will see you are
implementing DataSet, and EntityTable will be a DataGrid, but one point will
be different, DataSet designed by a large team and provides solutions to
wider situations.


hi scott,

hi scott,

这是我们采取的方法。它为我们提供了许多优点,而不是简单的属性值(特别是在对象持久性方面),但仍然没有解决你正在处理的问题。


告诉我更多关于这一点,因为我也想实现这个,

但是我仍然害怕使用自己的物品作为财产(我们称之为
它是一个EntityValue)而不是一个简单的值可能会导致巨大的内存消耗。当用户获取1000个实体,并且每个实体都拥有10个自己的实体值时,这些实体值将会有-let表示 - 5个拥有

值,这将是:


1000 * 10 = 10.000个引用

= EntityValue引用的开销为40kb
$ 000 $ b + 10.000的开销为80kb EntityValue'本身

= 120 k


然后还有EntityValue的值...

(告诉我,如果我计算错了)


我只是在这里,因为我也将每个获取的实体缓存在一个

EntityCache中,

内存导致了非常好的性能。

我不认为你想在业务对象上设置字段的可见性本身。这将
业务对象与UI结合在一起,可能会有一些地方名字
应该是可见的,而其他地方则不应该看到。
This is the approach we took. It provides many advantages to us over simple
property values (especially in the area of object persistence), but still
doesn''t solve the problem you are tackling.
tell me more about this, because i was thinking to implement this too,
but i''m still afraid that using an own object for a property (lets call
it an EntityValue) instead a simple value might lead to huge memory
consume. when a user fetch 1000 entities, and each of them have 10 own
EntityValue''s and those EntityValues would have -lets say- 5 own
values, this would be:

1000 * 10 = 10.000 references
= 40 kb overhead for the EntityValue references
+ 80 kb overhead for the 10.000 EntityValue''s itself
=120 kb

and then there also the values of the EntityValue...
(tell me if i calculated wrong)

i''m just afriad about this, since i also cache each fetched entity in a
"EntityCache", which leads to a very nice performance at the expense of
memory.
I don''t think you want to set
visibility of a field on the business object itself. That''s coupling the
business object to the UI and there may be some places where firstname
should be visible and others where it should not.




hmm对。我只想保留符号和最大值。

业务逻辑中的长度,因为这是语言。公司谈话和

将这些东西放在一个地方也很不错。


@the crow:

是的,但为此开发一个自己的控件,导致一种有效的方式实现你真正需要的东西,而不是创建一个

实体 - >数据集映射并获得satistied与datagrid。

问题也是,所有这些东西都不是开源的,所以每当一个

小改变可能对你有所帮助时,没办法。

史蒂文。



hmm right. i only want to keep the notation and the max. length in the
business logic, because this is the "language" the company talks and
have those things in one place is also nice.


@the crow:
yep, but developing an own control for this, leads to an effective way
to implement those things you realy need instead creating an
entity->dataset mapping and get satistied with the datagrid. the
problem is also, that all that stuff is not open-source, so whenever a
small change might help you, no way.
steven.


这篇关于将业务实体填充到UI中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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