Hello, I have such a question. I am writing a chat application on asp.net api. I want the messages to be saved in sql server. To do this, I created a user table in sql server with fields id, name, message. In visual studio connected this table. How to make so that messages were stored in sql server?

  • I vote for closing this question as not relevant, because the answer to this question can be found in the documentation for ASP.Net and can be easily found in Google or another search engine. - Sergey
  • one
    Maybe TC just doesn’t know where to dig, because it is not entirely clear in the question what it means "In visual studio I connected this table" - hardsky
  • Model ado.net edm - Oleg

1 answer 1

If you already have a model (EF context), and there is a specific place where you need to save the message (action on the server), the code will look something like this:

using (var context = new MyContext()) { context.Users.Add(new User { Name = data.Name, Message = data.Message }; context.SubmitChanges(); } 

where data is the object that came to the eshkn with the username and message.