实体框架中的实体抽象

实体框架中的实体抽象

本文介绍了实体框架中的实体抽象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,



我正在做一些实验,尝试使用Entity Framework建模一些东西,目的是最终学会如何使用它和它许多功能...



想象一下,在您的应用程序中有一个实体,这是您的应用程序的用户。用户可以使用几种不同的方法进行身份验证(使用电子邮件,Facebook,Twitter等),我个人遵循以下规则:

1.用户必须至少拥有一种身份验证方法已注册。

2.可以应用多种身份验证方法来匹配同一个用户。

3.每种身份验证方法都与其参数一起单独存储。

4.通常,如果我们在我们的应用程序中添加新的身份验证方法,我们就不想更改现有实体。



我写了一个通用的假设实现接口的认证实体(在所有认证方法中唯一共同的是存在用户标识符),使用任何认证方法注册/认证用户的算法。



现在,我想用EF做同样的事情。我想创建一组实体,每个实体都包含进行身份验证所需的信息,并将身份验证用户连接到其配置文件。当然,我可以天真地做,并写出太多的代码。



使用EF这样做的最佳方式是什么?



非常感谢!

Hey,

I''m doing some experiments, trying to model some stuff using Entity Framework, in purpose to eventually learn how to work with it and its many features...

Imagine having an entity in your application, which is your Application''s User. The user can authenticate in several different methods (Using Email, Facebook, Twitter, etc.), I personally follow the following rules:
1. A User must have at least a single authentication method through which he is registered.
2. Multiple authentication methods can be applied to match the same user.
3. Each authentication method is stored separately along with its parameters.
4. Typically if we add a new authentication method to our app, we wouldn''t like to change existing entities.

I have written a generic algorithms which register/authenticate a user using any authentication method, assuming an authentication entity which implements an interface (the only thing in common among all authentication method is the existence of a user identifier).

Now, I would like to do the same using EF. I want to create an set of entities, each entity holds the information required for the authentication to take place and connects the authenticating user to its profile. Of course that I could do it naively, and write way too much code.

What is the optimal way to do so using EF?

Thanks A Lot!

推荐答案


这篇关于实体框架中的实体抽象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-26 13:25