2013-05-05 46 views
1

我试图将我的DbSet移至将用于数据库操作的类库项目。将简单成员资格证书功能移至类库项目

我一直在关注this教程到Code First/SimpleMembershipProfider项目。我已经通过class lib项目获得了充满新表等的数据库。

但我错过了webpages_表,你可以看到this图像。

这是我的DataContext类:

public class DataContext : DbContext 
{ 
    public DataContext() : base("DefaultConnection") 
    { 
    } 

    public DbSet<Orders> Orders { get; set; } 
    public DbSet<Appointment> Appointment { get; set; } 
    public DbSet<UserProfile> UserProfile { get; set; } 
} 

并为每DbSet我创建了一个CS文件。我复制了web.config中的connectionString,并将它放在类项目中的app.config中。这是app.config文件的样子:

<configuration> 
    <configSections> 
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /> 
    </configSections> 
    <connectionStrings> 
    <add name="DefaultConnection" connectionString="Data Source=.;Initial Catalog=aspnet-CodeFirst-test;Integrated Security=SSPI;" providerName="System.Data.SqlClient" /> 
    </connectionStrings> 

    <system.web> 
    <roleManager enabled="true" defaultProvider="SimpleRoleProvider"> 
     <providers> 
     <clear /> 
     <add name="SimpleRoleProvider" type="WebMatrix.WebData.SimpleRoleProvider, WebMatrix.WebData" /> 
     </providers> 
    </roleManager> 
    <membership defaultProvider="SimpleMembershipProvider"> 
     <providers> 
     <clear /> 
     <add name="SimpleMembershipProvider" type="WebMatrix.WebData.SimpleMembershipProvider, WebMatrix.WebData" /> 
     </providers> 
    </membership> 
    </system.web> 

    <entityFramework> 
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework"> 
     <parameters> 
     <parameter value="v11.0" /> 
     </parameters> 
    </defaultConnectionFactory> 
    </entityFramework> 
</configuration> 

我不知道做什么用的过滤器文件夹(具有类InitializeSimpleMembershipAttribute)在我webproject做。

有人能告诉我如何获得在数据库中创建的webpages_?以及如何将websecurity等移动到类lib项目?

在此先感谢!

+0

您是否试图控制'SimpleMembership'并将其包含在您的项目实体框架中? – Komengem 2013-05-05 17:03:38

回答

1

如果您试图控制Asp.net简单会员表和/或将Asp.net简单会员表作为您的实体框架模型的一部分,您的项目实体框架,则需要执行多个步骤。我会一步一步解释他们,但这需要很长的时间,所以我只会提供给你参考。

Including Asp.net Simple Membership Tables as Part of Your Entity Framework Model

Seed Users and Roles with MVC 4, SimpleMembershipProvider, SimpleRoleProvider, Entity Framework 5 CodeFirst, and Custom User Properties

Building Applications with ASP.NET MVC 4. You can use trial version on pluralsight

如果您有任何具体问题,我会很乐意回答他们。

+0

嗨,所以我看到我必须创建表“webpages_Membership”和角色和oauth等,我自己。在第二个链接中,我遵循的教程,我没有看到这4个表中的任何一个正在创建?另一个问题是,如果我想从我的类库项目中种下用户等,我必须在那里创建它才能实现它? – Yustme 2013-05-05 17:41:41

+0

@Yustme您可以手动创建表格,以便您拥有控制权,并且可以将它们放在您想要的任何位置。这样,您可以为整个应用程序使用相同的连接字符串。种子用户,你将不得不启用迁移,第二个链接会谈到这一点。 – Komengem 2013-05-05 17:45:42

+0

大量的和平正好落入他们的位置。谢谢! – Yustme 2013-05-05 20:35:06