2013-06-14 3 views
6

私は例えば、私は単一のテーブルのスキーマをspecifiyすることができますEntityTypeConfiguration<Role>派生クラスからこの抜粋で指定したユーザーのロール多対多の関係を持っている:多対多リレーションシップテーブルのスキーマを指定する方法は?

[Schema(SchemaNames.ParkPay)] 
class WeekDayConfig : EntityTypeConfigurationWithSchema<WeekDay> 
{ 
    internal WeekDayConfig() 
    { 
     Ignore(t => t.IsDeleted); 
     Property(p => p.Name) 
      .IsRequired() 
      .HasMaxLength(20); 
    } 
} 

Roleのために、設定をクラスにこのコードが含まれていて、結果のテーブルUserRoleが、希望のスキーマではなく 'dbo'スキーマで作成されます。これがそのコードです:

[Schema(SchemaNames.ParkPay)] 
internal class RoleConfig : EntityTypeConfigurationWithSchema<Role> 
{ 
    public RoleConfig() 
    { 
     HasMany(t => t.Users) 
      .WithMany(t => t.Roles) 
      .Map(m => 
        { 
         m.ToTable("UserRole");        
         m.MapLeftKey("RoleId"); 
         m.MapRightKey("UserId"); 
        }); 
    } 
} 

は、私が「parkpay」スキーマではなく「DBO」スキーマの下に作成されたテーブルUserRoleを持つように、初期の播種期にスクリプトスキーマの変更を除いて、何かできることはありますか?

+2

あなたはこれを試してみましたか? ToTableのオーバーロードのように見えます:http://stackoverflow.com/questions/6028375/entity-framework-code-first-many-to-many-setup-for-existing-tables – rliu

答えて

10

これが動作しない理由を私は見ていない:

public RoleConfig() 
{ 
    HasMany(t => t.Users) 
    .WithMany(t => t.Roles) 
    .Map(m => 
    { 
     m.ToTable("UserRole","parkpay");        
     m.MapLeftKey("RoleId"); 
     m.MapRightKey("UserId"); 
    }); 
} 
+1

私はそれもしません。ありがとう、私はその過負荷を逃した。 – ProfK

+0

これを行うDataAnnotationsの方法はありますか? – RoLYroLLs

関連する問題