English 中文(简体)
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, works 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()?





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签