How would you use Entity Framework (1.0) with ASP.Net Membership?

后端 未结 1 1615
轮回少年
轮回少年 2021-01-12 02:25

I\'m trying to design an entity model for an application that uses ASP.Net membership for it\'s user authentication. In most of the database schemas I create, records typic

1条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-12 03:21

    My advice is: "Don't."

    Let me be more specific.

    Using UserId as a mapped, foreign key ties your entity model not to ASP.NET Membership in general, but to the SQL Membership Provider in general. What happens if you then want to use domain authentication or OpenID?

    Don't get me wrong: 99.9% of the time it's correct to tie DB references together with a foreign key. Heck, you could even do it here, but don't map it into your entity model. You need to keep a wall of logical separation between membership providers and your own data. You access your data through the EF. You access membership data through the membership API. The fact that they happen to live in the same DB because you happen to be using the SQL membership provider is an implementation detail.

    Update: I've expanded upon this idea in a blog post.

    0 讨论(0)
提交回复
热议问题