LINQ - Events?

WorldRacer

Erfahrenes Mitglied
Hallo zusammen,

ich versuche gerade irgendwie an Events zur Mitteilung einer Tabellenänderung zu kommen.

Also Szenario sieht wie folgt aus: Ich habe eine Klasse ContactContainer, die das TableAttribut besitzt.

C#:
[Table(Name = "System_Social_ContactContainer")]
    public class ContactContainer : Common.NotifyPropertyChangedObject
    {
        private EntitySet<ContactProvider> _contactProviders = new EntitySet<ContactProvider>();
        private EntitySet<ContactAttribute> _contactAttributes = new EntitySet<ContactAttribute>();

        /// <summary>
        /// Gets or sets the container ID.
        /// </summary>
        /// <value>
        /// The container ID.
        /// </value>
        [Column(Name = "ContainerID", IsPrimaryKey = true, IsDbGenerated = true, CanBeNull = true)]
        public Int32 ContainerID { get; set; }

        /// <summary>
        /// Gets or sets the container hash.
        /// </summary>
        /// <value>
        /// The container hash.
        /// </value>
        [Column(Name = "ContainerHash")]
        public String ContainerHash { get; set; }

        /// <summary>
        /// Gets or sets a collection of associated contact providers to gain access to the networking feature
        /// </summary>
        [Association(Name = "ContactContainer_ContactProvider", Storage = "_contactProviders", ThisKey = "ContainerID", OtherKey = "ContainerID", IsUnique = false)]
        public EntitySet<ContactProvider> ContactProviders
        {
            get
            {
                return this._contactProviders;
            }
            set
            {
                _contactProviders.Assign(value);
            }
        }

        /// <summary>
        /// Gets or sets a collection of contact attributes
        /// </summary>
        [Association(Name = "ContactContainer_ContactAttribute", Storage = "_contactAttributes", ThisKey="ContainerID", OtherKey = "ContainerID", IsUnique = false)]
        public EntitySet<ContactAttribute> ContactAttributes
        {
            get
            {
                return this._contactAttributes;                
            }
            set
            {
                _contactAttributes.Assign(value);
            }
        }

        public ContainerAttribute Attribute
        {
            get
            {
                return new ContainerAttribute(this);
            }
        }

        public class ContainerAttribute
        {
            private ContactContainer contactContainer;

            public ContainerAttribute(ContactContainer contactContainer)
            {
                // TODO: Complete member initialization
                this.contactContainer = contactContainer;
            }
            
            public ContactAttribute this[String key]
            {
                get
                {
                    ContactAttribute value = null;
                    if(contactContainer.ContactAttributes.Any(x => x.Key == key))
                        value = contactContainer.ContactAttributes.FirstOrDefault(x => x.Key == key);
                    return value;
                }
                set
                {
                    if (contactContainer.ContactAttributes.Any(x => x.Key == key))
                        contactContainer.ContactAttributes.FirstOrDefault(x => x.Key == key).Value = value.Value;

                    ContactAttribute attr = new ContactAttribute()
                    {
                        AttributeID = 0,
                        ContainerID = contactContainer.ContainerID,
                        Key = key,
                        Value = value.Value,
                    };
                    contactContainer.ContactAttributes.Add(attr);
                    
                    CoreIntelligence.Instance.RepositoryIntelligence.SubmitChanges();
                }
            }
        }
    }

Diese Klasse wird als Entität für die entsprechende Tabelle verwendet. Das Initialisieren, Abfragen und Ändern von Daten in der Tabelle funktioniert wunderbar. Hinterher landet alles in einem Property, das wie folgt aussieht:

Table<ContactContainer> contactContainer {get; set;}

Ich möchte allerdings jetzt Events darüber haben, ob z.B. ein ContactContainer eingefügt oder gelöscht worden ist. Ich arbeite mit einem DataContext.

Ist das irgendwie möglich?

Grüße
WR
 

Neue Beiträge

Zurück