实体框架代码第一个aspnet_Users映射/连接 [英] Entity Framework code first aspnet_Users mapping / joins

查看:121
本文介绍了实体框架代码第一个aspnet_Users映射/连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道Entity Framework 4.1的代码,首先你们如何处理涉及现有aspnet_Users表的查询?

I was wondering with Entity Framework 4.1 code first how do you guys handle queries that involve an existing aspnet_Users table?

基本上我需要一个涉及到aspnet_Users,以便我可以返回用户名:

Basically I have a requirement for a query that involves the aspnet_Users so that I can return the username:

SELECT t.Prop1, u.Username
FROM Table1 t 
INNER JOIN aspnet_User u ON t.UserId = u.UserId
Where t.Prop2 = true

理想情况下,我想:

from t in context.Table1
join u in context.aspnet_Users on t.UserId equals u.UserId
where t.Prop2 = true

但是我'不知道如何让aspnet_Users映射到一个类用户?如何使aspnet_Users成为我的dbset的一部分?

But I'm not sure how to get aspnet_Users mapping to a class User? how do I make aspnet_Users part of my dbset ?

任何帮助将不胜感激,谢谢提前

Any help would be appreciated, thanks in advance

推荐答案

不要映射aspnet_Users表或与aspnet相关的任何其他表。这些表具有自己的数据访问和他们自己的访问逻辑。映射这些表将引入代码重复,可能的问题,并分解问题。如果您需要用户查询,请创建仅包含id,用户名,电子邮件和映射视图等所需信息的视图。关键是视图将只读,它将只包含允许的数据,您的应用程序不会意外地修改这些数据而不使用ASP.NET API。

Don't map aspnet_Users table or any other table related to aspnet. These tables have their own data access and their own logic for accessing. Mapping these tables will introduce code duplication, possible problems and breaks separation of concerns. If you need users for queries, create view with only needed information like id, user name, email and map the view. The point is that view will be read only, it will contain only allowed data and your application will not accidentally modify these data without using ASP.NET API.

这篇关于实体框架代码第一个aspnet_Users映射/连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆