This is a migrated thread and some comments may be shown as answers.

Binding to a Transient Property

3 Answers 75 Views
Design Time (Visual Designer & Tools)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Stuart Hemming
Top achievements
Rank 2
Stuart Hemming asked on 18 Jul 2010, 01:31 AM
I have a class that includes a transient property...
[Telerik.OpenAccess.Persistent(IdentityField = "id")]
public class MyClass
{
    int id;
    string name;
    [FieldAlias("id")]
    public int ID
    {
        get
        {
            return id;
        }
        set
        {
            id = value;
        }
    }
    [FieldAlias("name")]
    public string Name
    {
        get
        {
            return name;
        }
        set
        {
            name = value;
        }
    }
    [Telerik.OpenAccess.Transient()]
    public string Note;
}

Now, I'm getting an instance of MyClass from the DB using something like this...

var x = from c in Scope.Extent<MyClass>()
        where c.ID.Equals(99)
        select c;

Then I'm populating my 'Note' property locally...

MyClass myClass = x.FirstOrDefault();
if(myClass != null)
{
  myClass.Note = "blah";
}

Finally, I'm creating an IEnumerable that includes my "myClass" object and binding that as the DataSource of an asp:DetailsView.

If I look at the object assigned to the DetailsView.DataSource property I can see the Note property and I can see that it is populated.

However, the markup contains this ...

<asp:Label ID="Notes" runat="server" Text='<%# Eval("Note") %>' />

And the system reports an exception when trying to execute it. The exception reads "DataBinding: 'RSD.Model.MyClass' does not contain a property with the name 'Note'."

I don't understand why.

Can anyone shed any light on this for me?

TIA
-- 
Stuart

3 Answers, 1 is accepted

Sort by
0
Stuart Hemming
Top achievements
Rank 2
answered on 18 Jul 2010, 01:44 AM
Go figure!

I've spent ages trying to work this out only to admit defeat and ask here for help.

10 Minutes later and I'm struck by an idea and it works!!

The trick, it appears is to change the class definition like this ...

[Telerik.OpenAccess.Persistent(IdentityField = "id")]
public class MyClass
{
    int id;
    string name;
    [Telerik.OpenAccess.Transient()]
    public string note;
 
    [FieldAlias("id")]
    public int ID
    {
        get
        {
            return id;
        }
        set
        {
            id = value;
        }
    }
    [FieldAlias("name")]
    public string Name
    {
        get
        {
            return name;
        }
        set
        {
            name = value;
        }
    }
    [FieldAlias("note")]
    public string Note
    {
        get
        {
            return note;
        }
        set
        {
            note = value;
        }
    }
}

I'd love to know if this works 'cos this is how it's supposed to be done or it's just a happy accident.

In any event, I can go to bed happy now!

-- 
Stuart
0
Accepted
Zoran
Telerik team
answered on 19 Jul 2010, 11:41 AM
Hello Stuart Hemming,

 Yes the last setup that you did is a correct one in order to be able to bind an ASP .NET control to a datasource representing this class. The problem in the first case was that Note was declared as a field of the class instead of a property. The ASP .NET controls are looking for properties of a class when they perform data binding, so that is why "Note" was not visible. When you created the transient field "note" and then wrapped it up in a property, the details view is able to see the "Note" property and bind to it. I can only point you out that the "FieldAlias" attribute on the property that points to this transient field is not required, but however it does not cause any problems for the runtime if you have it.

Sincerely yours,
Zoran
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Stuart Hemming
Top achievements
Rank 2
answered on 19 Jul 2010, 11:50 AM
Cheers Zohan,

I'm learning that there are shedloads of things that I could learn about OA, but I have to say I am struggling to get much help from the docs.

Still nice to know I'm going in the right direction.

-- 
Stuart
Tags
Design Time (Visual Designer & Tools)
Asked by
Stuart Hemming
Top achievements
Rank 2
Answers by
Stuart Hemming
Top achievements
Rank 2
Zoran
Telerik team
Share this question
or