问题描述
人们,
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.
推荐答案
这是我们采取的方法。它为我们提供了许多优点,而不是简单的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.
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中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!