Click here to Skip to main content
15,892,839 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

This is my code :
C#
public List<notificationdata> ReadNotification(int memberId, int NotificationId)
       {
           using (KiwiDbContext context=new KiwiDbContext(_ConnectionString))
           {
               NotificationData nd = new NotificationData();
               nd.IsRead = true;

               var query = (from n in context.Notifications where n.MemberID == memberId && n.NotificationID == NotificationId && n.IsRead == false select new NotificationData { NotificationID = n.NotificationID, Message = n.Message, CreatedTime = n.NotificationTime, IsRead = nd.IsRead });
               return query.ToList();


               context.SaveChanges();
           }


Execution is done but not saving to database table.

Please give me correct code for that.

Thanks
Posted
Updated 4-Oct-15 20:01pm
v2
Comments
Krunal Rohit 5-Oct-15 2:14am    
You're reading from the DB, why do you need to save it ?
-KR
Sinisa Hajnal 5-Oct-15 2:41am    
Did you check the result? Do you even get anything in query.ToList()?

1 solution

As your posted code it is just reading the data from database not saving the data to database. To Save data you have to code like

public void AddNotification(string msg, bool readable)
       {
           using (KiwiDbContext context=new KiwiDbContext(_ConnectionString))
           {
               NotificationData nd = new NotificationData();
               nd.IsRead = readable; 
               nd.Message = msg;
               nd.CreatedTime = DateTime.Now;
               context.Notifications.Add(nd);              
               context.SubmitChanges();
           }
        }
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900