DotNetOpenAuth - Database.DataContext.AddToUser(user) does not work
I am incorporating DotNetOpenAuth to my asp.net website. I am new with Entity framework. Database.DataContext.AddToUser(user) located in LogingFrame.aspx.cs does not add a user into the database. User and AuthenticationToken records are filled correctly. The same code from template project, which points to the same database, 开发者_如何学JAVAworks fine. Probably I missed something during incorporation. Could you please point what I have to check? Please let me know if you need any code to be provided.
...does not add a user into the database. User and AuthenticationToken records are filled correctly.
Your question seems to contradict itself, or I'm reading it wrong. It sounds like you're saying no user is added, but then a user is added.
Let me take a stab at it though and let you know how this project template works. A database transaction wraps all database changes within a single HTTP request. It's built into the RelyingPartyLogic assembly to have this behavior. Also, at the end of a successful HTTP request (one that didn't result in an unhandled exception) SaveChanges() is called and the transaction is committed. If an unhandled exception is thrown, the changes and transaction are rolled back. This helps to protect the integrity of your database.
A side-effect of this is, however, that if you're debugging through an "add a user" method and after you see AddToUser
executed you jump to the users table to see if it was added, it won't be there because SaveChanges hasn't yet been called and the transaction hasn't been committed yet.
Per standard Entity Framework behavior, SaveChanges must be called for your changes to be persisted in the database, but as I said before, the RelyingPartyLogic library makes this call for you. But you may sometimes need to call SaveChanges yourself in your own code in order to (for example) get the ID of a newly added row. This works even within a transaction before committing it.
Hope that helps.
Did you forget to call DataContext.SaveChanges()?
精彩评论