New Posts New Posts RSS Feed: Trigger Verifier - Dictionary ...
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Trigger Verifier - Dictionary ...

 Post Reply Post Reply
Author
as123 View Drop Down
Newbie
Newbie


Joined: 27-Apr-2010
Posts: 30
Post Options Post Options   Quote as123 Quote  Post ReplyReply Direct Link To This Post Topic: Trigger Verifier - Dictionary ...
    Posted: 08-Dec-2010 at 12:01am
        Is it possible to trigger a verifier when a dictionary value changes? 

        For example, let us say we have a  Dictionary<TKey, Tvalue> called PhoneList on the Employee entity as a property. This dictionary is created at runtime.  Also, the PhoneList is bound to SilverLight text fields (PhoneList["Business"] for business phone number entry)

      How to specify TriggerItem to fire verification based on changes to a specific entry (for example, PhoneList["Business"] in the dictionary, or any change (change to "Business", "Home" or "Mobile" dictionary entries) for that matter? 

      The SilverLight binding to the dictionary item (PhoneList["Business"]) works ok, but not sure on what property the trigger should be specified. 

Thanks

Sample scenario:

public class Employee: Entity
{

       public int EmpNumber;

       public string Name;

        public Dictionary<string, string> PhoneList  {get;  set;}

        ...
}
Back to Top
DenisK View Drop Down
IdeaBlade
IdeaBlade


Joined: 25-Aug-2010
Posts: 715
Post Options Post Options   Quote DenisK Quote  Post ReplyReply Direct Link To This Post Posted: 09-Dec-2010 at 8:05pm
Hi as123;

After a few hours thinking about this, I finally consulted with my senior developer and this is what he has to say:

@as123 - Having trouble understanding the scenario.

The code you've written is - how do I say this - impossible. There is no UI control that returns a dictionary. You can't set this property to a dictionary that a user would enter.

The binding that you think is successful is, in fact, reading a value out of the dictionary and putting it on screen. You are binding to a value in the dictionary, not to the dictionary itself.

Perhaps you are trying to change a value in the dictionary? If so, where is that value going?

Usually an entity property is changeable only if the value will end up in the database record. No EF-supported table column can take multiple values (or a dictionary). So if you're trying to find a way to stick multiple phone numbers in the Employee ... this doesn't look like it will work.

Maybe you're trying to do something different? Maybe you're trying to classify the phone number as a Home, Business, Cell phone? Maybe that classification is stored in the Employee record? If that's the case, let me know and we can talk about how to do it.

Sorry but I can't help until I understand what you are doing. You may want to forget about the UI for a moment and provide an example of code that reads and writes to this PhoneList property. Then I might see what you're trying to do and be able to help.
Back to Top
as123 View Drop Down
Newbie
Newbie


Joined: 27-Apr-2010
Posts: 30
Post Options Post Options   Quote as123 Quote  Post ReplyReply Direct Link To This Post Posted: 09-Dec-2010 at 9:23pm

            May be, I oversimplified the Dictionary case  in the sample.  The dictionary is derived from a child table of Employee (say, EmployeeContact) after retrieving the child entities for Employee. The dictionary is used so that the data can be shown as simple properties of Employee itself (rather than in a Master-Detail window), but persisted into the database as data in the child table. In fact, in our scenario, EmployeeContact could have different types of data (Phone Number, E-mail etc.) as the Contact type is configurable by the user, and let us ignore that complexity for now. As you have correctly pointed out, the UI is binding to a dictionary value and NOT to the dictionary itself.

 

            Ignoring the UI and other complexities for now, what I am trying to do is simply trigger validation when a dictionary value is changed, similar to the way any simple Entity property is changed. In this case, the property (dictionary) of the Employee is not changed directly, but a value within the dictionary.

 

            I hope the problem situation is clear now. If not, please let me know.

 

Thanks
Back to Top
smi-mark View Drop Down
DevForce MVP
DevForce MVP
Avatar

Joined: 24-Feb-2009
Location: Dallas, Texas
Posts: 343
Post Options Post Options   Quote smi-mark Quote  Post ReplyReply Direct Link To This Post Posted: 10-Dec-2010 at 8:41am
Hi,

You say that this data is taken from "EmployeeContact". Surely the EmployeeContact table then has a type column of some sort, indicating that it is a business/mobile/etc number?

Why not implement verification in this EmployeeContact class and have logic that defines what to do for specific types?

If you show us a screenshot or write out how your Employee / Contact tables, we can help you with some sample code.

Rather than:
public Dictionary<string, string> PhoneList  {get;  set;}

could you not do something like this:

public Dictionary<string, EmployeeContact> Contacts { get; set; }

then bind to Contacts["Business"].PhoneNumber ? This would then expose it as an IdeaBlade Entity and you would then have full property changed / verification capabilities.

Edited by smi-mark - 10-Dec-2010 at 8:43am
Back to Top
as123 View Drop Down
Newbie
Newbie


Joined: 27-Apr-2010
Posts: 30
Post Options Post Options   Quote as123 Quote  Post ReplyReply Direct Link To This Post Posted: 10-Dec-2010 at 9:27am
        Your suggestion to implement the verification in the child class property rather than trying to do on the dictionary in the parent seems to be the way to go.  Thanks for your help.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down