2013-05-05 20 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