2011-12-30 7 views
2

これは簡単な質問のようですが、答えが見つからないようです。MVCモデルを別のテーブルにバインドする方法

私はこのようになりますモデルを持っている...

public class Application 
{ 

    public int Id { get; set; } 
    public string Title { get; set; } 
    public string LeadProgrammer { get; set; } 
    public string ConnectionStringCode { get; set; } 
} 

public class ApplicationDBContext : DbContext 
{ 
    public DbSet<Application> Applications { get; set; } 
} 

私の実際のテーブル名はDBA_APPLICATIONSです...モデルは、もちろん、ただdbo.Applicationsを探しています。このルーティングを実際のテーブルに変更するにはどうすればよいですか?

+0

マッピングを調べましたか?クラス名は別のテーブル名にマッピングできます。 –

+1

可能な複製http://stackoverflow.com/questions/3276955/change-db-table-name-in-ef4-entity-framework-4 –

答えて

4

ApplcationDBContextクラスにこれを追加します。

public class ApplicationDBContext : DbContext 
{ 
    public DbSet<Application> Applications { get; set; } 

    protected override void OnModelCreating(DbModelBuilder modelBuilder) 
    { 
     modelBuilder.Entity<Application>().ToTable("DBA_APPLICATIONS"); 
     // otherwise EF assumes the table is called "Applications" 
    } 
} 
関連する問題