Asp 2.0 Bind on Entity property

Posts   
 
    
barabba
User
Posts: 5
Joined: 27-Jan-2010
# Posted on: 27-Jan-2010 16:55:31   

Hello, I am using LLBLGenProDataSource2 for data binding in asp.net 2.0 project: version 2.6 Final ( SD.LLBLGen.Pro.ORMSupportClasses.NET20 is version 2.6.8.612). I have an addition on my PlaceCustumer entity (PlaceCustumerEntity.cs):


public CustumerAttributes Attributes
        {
            get
            {
                if (_attributes == null)
                {
                    _attributes = CreateAttributesObject();
                }

                return _attributes;
            }
            set
            {
                if (value != _attributes)
                {
                    _attributes = value;
                }
            }
        }

In my form I have the following code:



<llblgenpro:LLBLGenProDataSource2 ID="ldsCustumerEntity" runat="server" 
    OnPerformWork="Lds_OnPerformWork"
    OnPerformSelect="Lds_OnPerformSelect"
    DataContainerType="EntityCollection" LivePersistence="false" 
    CacheLocation="Session"
    AdapterTypeName="Place.DAL.DatabaseSpecific.DataAccessAdapter, Place.DALDBSpecific" 
    EntityFactoryTypeName="Place.DAL.FactoryClasses.PlaceCustumerEntityFactory, Place.DAL">
</llblgenpro:LLBLGenProDataSource2>

<asp:FormView ID="FormView1" DataSourceID="ldsCustumerEntity"
    DataKeyNames="Id"  
    DefaultMode="Edit" runat="server">
    <EditItemTemplate>

<asp:TextBox ID="TxtPlace" runat="server" Text='<%# Bind("Place") %>' />
<asp:TextBox ID="TxtName" runat="server" Text='<%# Bind("Attributes.NameCustomer") %>' />
<asp:Button ID="btnSubmit" 
            OnClick="btnSubmit_Click"
            CommandName="Update" runat="server" Text="Save" />
    </EditItemTemplate>
</asp:FormView>

In the C# code this:



ListItemViewModel< PlaceCustumerEntity> _selectedItem;
public void LoadData(ListItemViewModel< PlaceCustumerEntity> selectedItem)
{
        if (selectedItem != null)
        {
             _selectedItem = selectedItem;
             ldsCustumerEntity.Select();
        }
}

protected void Lds_OnPerformSelect(object sender, PerformSelectEventArgs2 e)
    {
        if (_selectedItem != null)
        {
            ldsCustumerEntity.EntityCollection.Clear();
            ldsCustumerEntity.EntityCollection.Add(_selectedItem.Entity);   
        }
    }



When asp run the code, data binding works. LoadData() is called data "Attributes.NameCustomer" and "Place" are correctly displayed in the form. This works has expected. Then I have changed the field "Place", and the property "Attributes.NameCustomer" using the web form. Now the problem: when I click on the save button, entity is changed, but only on the field "Place". The entity property "Attributes.NameCustomer" is unchanged.
Does Bind only apply on entity fields that are mapped on the database and not on custumer properties? After I have modified "Attributes.NameCustomer" the form disappear when I click the save button.

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 27-Jan-2010 18:35:00   

SD.LLBLGen.Pro.ORMSupportClasses.NET20 is version 2.6.8.612

Let's start by sing the latest runtime library build, you are using a very old one.

barabba
User
Posts: 5
Joined: 27-Jan-2010
# Posted on: 28-Jan-2010 10:29:51   

Sorry i posted an incorrect version number. The version of my SD.LLBLGen.Pro.ORMSupportClasses.NET20.dll is 2.6.9.1202.

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 28-Jan-2010 11:56:04   

Please try the following: 1- Add a new property:

        public string NameCustomer
        {
            get
            {
                if (_attributes == null)
                {
                    _attributes = CreateAttributesObject();
                }

                return _attributes.NameCustomer;
            }
            set
            {
                if (value != _attributes.NameCustomer)
                {
                    _attributes.NameCustomer = value;
                }
            }
        }

2- Bind to it:

<asp:TextBox ID="TxtName" runat="server" Text='<%# Bind("NameCustomer") %>' />

Would this work?

barabba
User
Posts: 5
Joined: 27-Jan-2010
# Posted on: 28-Jan-2010 14:00:10   

Walaa wrote:

Please try the following: 1- Add a new property:

        public string NameCustomer
        {
            get
            {
                if (_attributes == null)
                {
                    _attributes = CreateAttributesObject();
                }

                return _attributes.NameCustomer;
            }
            set
            {
                if (value != _attributes.NameCustomer)
                {
                    _attributes.NameCustomer = value;
                }
            }
        }

2- Bind to it:

<asp:TextBox ID="TxtName" runat="server" Text='<%# Bind("NameCustomer") %>' />

Would this work?

yes, your suggestion works. Does Bind("Attributes.NameCustomer") an hierarchical binding problem?

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 29-Jan-2010 01:39:01   

barabba wrote:

yes, your suggestion works. Does Bind("Attributes.NameCustomer") an hierarchical binding problem?

Yes, I think so, as you are creating such attributes on the fly, so binder can't resolve it.

David Elizondo | LLBLGen Support Team
barabba
User
Posts: 5
Joined: 27-Jan-2010
# Posted on: 29-Jan-2010 13:34:07   

I have stepped into the code and it seam that LLBLGenProDataSource2 uses reflection to set the value "NameCustomer". For other fields, it use the function SetNewFieldValue. I have stepped the code with the suggested modifications.

Is it possible that for properties like "Attributes.NameCustomer" the property descriptor is not correctly solved inside the LLBLGenProDataSource2 ExecuteUpdate() function?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39865
Joined: 17-Aug-2003
# Posted on: 01-Feb-2010 10:47:41   

barabba wrote:

I have stepped into the code and it seam that LLBLGenProDataSource2 uses reflection to set the value "NameCustomer". For other fields, it use the function SetNewFieldValue. I have stepped the code with the suggested modifications.

Is it possible that for properties like "Attributes.NameCustomer" the property descriptor is not correctly solved inside the LLBLGenProDataSource2 ExecuteUpdate() function?

It uses reflection because the property NameCustomer isn't a known field, so it can't use SetNewFieldValue, and it has to use the property descriptor to set the property value. I think what goes wrong is that "Attributes.NameCustomer" is the name specified and the property descriptor of that name isn't found (as it first has to determine the property 'Attributes' and then the property 'NameCustomer' on that instance. It's then of course the question, what to do if Attributes is null, but that's the problem of the developer.

SetEntityValues in LLBLGenProDataSourceViewBase simply obtains the properties and then looks up the property to set for the values specified. As the property name is 'Attributes.NameCustomer', it's not found. So we have to alter the method. We'll set up a test case to see if the changes we have in mind are fixing your problem.

Frans Bouma | Lead developer LLBLGen Pro
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39865
Joined: 17-Aug-2003
# Posted on: 01-Feb-2010 11:51:06   

I've added code to the method to traverse inner properties, if the property name isn't found. This made it possible to set the inner property. I've attached the dll which makes this possible, please try it in your application to see if it works for you too (I've used the same setup as you used, it's usable in selfs. and adapter).

Frans Bouma | Lead developer LLBLGen Pro
barabba
User
Posts: 5
Joined: 27-Jan-2010
# Posted on: 01-Feb-2010 12:27:02   

Otis wrote:

I've added code to the method to traverse inner properties, if the property name isn't found. This made it possible to set the inner property. I've attached the dll which makes this possible, please try it in your application to see if it works for you too (I've used the same setup as you used, it's usable in selfs. and adapter).

Thank you it works!