Breeze,数据库优先和匿名对象

时间:2014-02-23 16:55:29

标签: asp.net entity-framework breeze

我正在使用ASP.Membership提供程序,我已经为用户数据创建了一个附加表。我只是在试验,我并不担心安全性或类似的东西。我只关心大局。

我正在尝试使用Breeze,SPA,实体框架和Web.API,也许在我掌握各个概念之前,我的速度太快了。

My Breeze查询如下所示:

[HttpGet]
public IQueryable<object> Users()
{
    return (
        from user in _contextProvider.Context.Users
        join membership in _contextProvider.Context.Memberships on user.UserId equals membership.UserId
        join userProfile in _contextProvider.Context.UserProfiles on user.UserId equals userProfile.UserId
        select new { user, membership, userProfile}
    );
}

我的结果如下所示(仅显示第一条记录):

{
$id: "1",
$type: "<>f__AnonymousType4`3[[SPA01.EntityFramework.User, SPA01],[SPA01.EntityFramework.Membership, SPA01],[SPA01.EntityFramework.UserProfile, SPA01]], SPA01",
user: {
    $id: "2",
    $type: "SPA01.EntityFramework.User, SPA01",
    UserId: "dd59fcd1-9d88-4494-a37c-1c25155cb77d",
    ApplicationId: "23042eba-1113-4e56-8ac6-4640120ecc6c",
    UserName: "DHaworth",
    IsAnonymous: false,
    LastActivityDate: "2014-02-17T00:01:39.707",
    Membership: {
        $id: "3",
        $type: "SPA01.EntityFramework.Membership, SPA01",
        UserId: "dd59fcd1-9d88-4494-a37c-1c25155cb77d",
        ApplicationId: "23042eba-1113-4e56-8ac6-4640120ecc6c",
        Password: "sdfasdfsadfsadfsafasfae0dfzT64vo=",
        PasswordFormat: 1,
        PasswordSalt: "/CRUMPNf9+byEdPraeasfsaQJw==",
        Email: "MyEmail@hotmail.com",
        PasswordQuestion: "TR",
        PasswordAnswer: "B4HOezQ/TYasdfasfasfgjz4oAOERhnc=",
        IsApproved: true,
        IsLockedOut: false,
        CreateDate: "2014-01-04T05:18:18.063",
        LastLoginDate: "2014-02-17T00:01:39.707",
        LastPasswordChangedDate: "2014-01-12T21:58:30.497",
        LastLockoutDate: "1754-01-01T00:00:00.000",
        FailedPasswordAttemptCount: 0,
        FailedPasswordAttemptWindowStart: "1754-01-01T00:00:00.000",
        FailedPasswordAnswerAttemptCount: 0,
        FailedPasswordAnswerAttemptWindowsStart: "1754-01-01T00:00:00.000",
        Comment: null,
        User: {
            $ref: "2"
        }
    },
    UserProfile: {
            $id: "4",
            $type: "SPA01.EntityFramework.UserProfile, SPA01",
            UserId: "dd59fcd1-9d88-4494-a37c-1c25155cb77d",
            FirstName: "Duane",
            LastName: "Haworth",
            User: {
            $ref: "2"
            }
    },
    Roles: [ ]
},
membership: {
        $ref: "3"
},
userProfile: {
        $ref: "4"
}

},

我正在创建一个用户管理界面,我将显示所有三个表格中的信息。

我是否可以在使用Breeze时使用JsonResultsAdapter执行此操作,还是需要先在Entity Framework端执行某些操作?

由于

1 个答案:

答案 0 :(得分:1)

Breeze支持这种情况(在匿名对象中包装实体)开箱即用;无需额外的工作。例如,请参阅lookup lists example。 Breeze客户端需要具有处理实体的元数据,但如果您使用EF和EFContextProvider,则没有问题。