以多对多关系映射两个表

时间:2013-11-19 03:03:32

标签: c# entity-framework-5 fluent-interface

我正在使用Fluent API实现实体框架和代码优先技术。

我已经有一个表的映射:

modelBuilder.Entity<Certificate>()
            .HasMany( c => c.Employees ).WithMany( e => e.Certificates )
                .Map( m => {
                    m.ToTable( "Employee_Certificate" );
                    m.MapLeftKey( "CertificateId" );
                    m.MapRightKey( "EmployeeId" );
                } );

我想知道的是,我是否还需要为员工实体进行等效映射?

类似的东西:

modelBuilder.Entity<Employee>()
            .HasMany( e => e.Certificates ).WithMany( c => c.Employees )
                .Map( m => {
                    m.ToTable( "Employee_Certificate" );
                    m.MapLeftKey( "EmployeeId" );
                    m.MapRightKey( "CertificateId" );
                } );

或简单的HasMany(...).WithMany(...)是否足够好?

0 个答案:

没有答案