c# - CollectionChanged handler from ObservableCollection is null when getting item from Database -
We are currently working on a project and I am working on any kind of warning / information system. Original Thoughts:
There are many questions, in each question there is an observation collection of answer items. All these items are saved in a SQL Server database (we are using the first method of unit framework code). Important parts of the question class:
public class questions {public question () {... answer = new observation qualification & lt; Answer & gt; (); ...} public virtual supervision qualification & lt; Answer & gt; Answer {Get; Set; } ... extra stuff omitted}
I want to add a collection handler to the compilation of the answer examples. I do this when I create a membership object for that question. This membership object is created and saved in my manager category which communicates with the reference of the database. Ways to do this:
Public Zero CreateQuestion Subscriptions (Int UserID, Int qu ID, Notification Frequency Information Frequency) {Regular Customer = _politiciOnlineDbContext.Regulars.SingleOrDefault (r = & gt; RSIIRI = = User-facing); Question Question = _politiciOnlineDbContext.Questions.SingleOrDefault (q = & gt; q.QuestionId == question id); If (question == zero; customer == faucet) return; questions. Answers.CollectionChanged + = New NotifyCollectionChangedEventHandler (Collection ChangedMethod); Question Membership Subscription Members Membership = New Question Membership () {Notification Frequency = Information Frequency, Question = Question, Subscriber = Subscriber, Wants E-mail = True}; _politiciOnlineDbContext.QuestionSubscriptions.AddOrUpdate (questionSubscription); _politiciOnlineDbContext.SaveChanges (); } Private Zero Collection Converged Method (Object Sender, NotifyCollectionChangedEventArgs E) {If (e.Action == NotifyCollectionChangedAction.Add) {Debug.WriteLine ("A reply has been added! (Sub" + ((Subscription) Sender) Subscriber. UserId + "+" + ((Question Subscription) Sender) Q. Quiz ID + ")"); (Subscribe) sender). Alter Add (New Alert (Subscription) Sender, AlertType Add Q & A Answer)); }}
When I do this, the handler is connected to the event of change in the Observation Collection collection. But it disappears quickly, when I get a question object from the database, there is no handler in the archived converted event.
It's rather logical, because I do not know how and how to be saved, but it's not what I want to achieve. To keep the database I need a handler, of course even when the objects are inserted into the database and receive. How can I do this?
Comments
Post a Comment