您的位置:首页 > 其它

XAF ORMDataModel构建的基础资料对象无法被调用显示的解决办法

2016-10-09 10:01 477 查看
修正,其实只要在基础资料类中加入[XafDefaultProperty("名称")]标签即可。

namespace NEO.ERP.Module.BusinessObjects.Business
{
//引用显示名称
[XafDefaultProperty("名称")]
public partial class 公共基础资料基类
{
public 公共基础资料基类(Session session) : base(session) { }

public override void AfterConstruction()
{
base.AfterConstruction();
}

}

}


下面的是老的引用方法。

在Module项目中如果手工增加的XPO Business Object类,增加了[XafDefaultProperty("名称")]属性后,该对象被别的类调用就可以显示一个下拉列表。

using System;
using DevExpress.Xpo;
using DevExpress.Data.Filtering;
using System.Collections.Generic;
using System.ComponentModel;
using DevExpress.Persistent.Base;
using DevExpress.ExpressApp.DC;
using DevExpress.ExpressApp;

namespace HelloXAF.Module.BusinessObjects.ORMDataModel_Base
{
[DefaultClassOptions]
[XafDefaultProperty("编码")]
public partial class 币别
{
public 币别(Session session) : base(session) { }
public override void AfterConstruction() { base.AfterConstruction(); }

public override string ToString()
{

//if (!isDefaultPropertyAttributeInit)
//{
string defaultPropertyName = string.Empty;
XafDefaultPropertyAttribute xafDefaultPropertyAttribute = XafTypesInfo.Instance.FindTypeInfo(GetType()).FindAttribute<XafDefaultPropertyAttribute>();
if (xafDefaultPropertyAttribute != null)
{
defaultPropertyName = xafDefaultPropertyAttribute.Name;
}
else
{
DefaultPropertyAttribute defaultPropertyAttribute = XafTypesInfo.Instance.FindTypeInfo(GetType()).FindAttribute<DefaultPropertyAttribute>();
if (defaultPropertyAttribute != null)
{
defaultPropertyName = defaultPropertyAttribute.Name;
}
}
if (!string.IsNullOrEmpty(defaultPropertyName))
{
var  defaultPropertyMemberInfo = ClassInfo.FindMember(defaultPropertyName);
object obj = defaultPropertyMemberInfo.GetValue(this);
if (obj != null)
{
return obj.ToString();
}
}
//isDefaultPropertyAttributeInit = true;
//}
//if (defaultPropertyMemberInfo != null)
//{
//    object obj = defaultPropertyMemberInfo.GetValue(this);
//    if (obj != null)
//    {
//        return obj.ToString();
//    }
//}
return base.ToString();
}
}

}


View Code
这样,设计器添加的基础资料也能显示出来了。



  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐