Sunday, August 2, 2009

Xaf tip #2

Just come back from my short holidays this year and I am feeling very relaxed. So I though I should continue my Xaf tips series as I encounter them in my every day work.

Be carefull of DevExpress.ExpressApp.DC.TypesInfo.FindTypeInfo method

imagine any kind of conflict you like taking into account that a new table named Person is going to be created at your db with the following lines

public override void CustomizeTypesInfo(ITypesInfo typesInfo)
{
    base.CustomizeTypesInfo(typesInfo);
    ITypeInfo personClassInfo = typesInfo.FindTypeInfo(typeof(Person));
    if (personClassInfo != null)
    {
        IMemberInfo personFullNameMemberInfo = personClassInfo.FindMember("FullName");
        var persistentAliasAttribute = personFullNameMemberInfo.FindAttribute<PersistentAliasAttribute>();
        if (persistentAliasAttribute == null)
            personFullNameMemberInfo.AddAttribute(new PersistentAliasAttribute("FirstName + MiddleName + LastName"));
    }
}

but not with those bellow which are almost the same

public override void CustomizeTypesInfo(ITypesInfo typesInfo)
{
    base.CustomizeTypesInfo(typesInfo);
    ITypeInfo personClassInfo = typesInfo.PersistentTypes.Where(info => info.Type == typeof(Person)).SingleOrDefault();
    if (personClassInfo != null)
    {
        IMemberInfo personFullNameMemberInfo = personClassInfo.FindMember("FullName");
        var persistentAliasAttribute = personFullNameMemberInfo.FindAttribute<PersistentAliasAttribute>();
        if (persistentAliasAttribute == null)
            personFullNameMemberInfo.AddAttribute(new PersistentAliasAttribute("FirstName + MiddleName + LastName"));
    }
}
Maybe FindTypeInfo name was not chosen correctly to express what it really does. Anyway I am happy that I know that now
Technorati Tags: ,,

Subscribe to XAF feed
Subscribe to community feed

DiggIt!

3 comments:

  1. Hello there,

    The TypeInfo instance, which is accessible through ITypeInfo is a single instance for the given TypesInfo. It can be created on-demand, but there should be no side-effects of doing this. Also, FindTypeInfo has nothing to do with PersistentTypes list and it should not have any side effects, so any calls to it should not change PersistentTypes. The only way to change PersistentTypes list is to call RegisterEntity. Lastly, tables are created by XPO only for types from the PersistentTypes list. If there is no Person in this list – there should be no Person table in the database. If you are saying that this is not how it works and you have found a bug, please contact me on garys@devexpress.com as I'll need more information to reproduce it.

    Thanks,
    Gary Short
    Technical Evangelist
    Developer Express

    ReplyDelete
  2. Gary thnks for jumping in and for the more info you provide. I was not carefull to what I said b4, maybe cause of my English :(. Anyway I have change my post a little to epxress me better

    ReplyDelete
  3. Hello Apostolis,

    Thanks for blogging about our products.
    We have read your post, and after a closer look at the problem, we found that this behavior is caused by a bug.
    We have registered it in our Support Center at http://www.devexpress.com/Support/Center/p/B39916.aspx
    Please track it in order to be notified when the problem is fixed.

    Thanks,
    Aleks M,
    R@D, .NET Team, DevExpress Inc.

    ReplyDelete