Quantcast
Channel: EntityFramework Reverse POCO Code First Generator
Viewing all articles
Browse latest Browse all 1642

New Post: (custom) Many to Many mappings

$
0
0
Hello,

I have question about mappings for Many to Many. Generally everything works great but I use Reverse POCO Generator with database that was created before with DevExpress XPO ORM. So mappings were generated other than the default. Example of this is on picture below:

http://i.imgur.com/ZQofe5M.png

This log-name table is mapping table and generator creates it as standard table and code like:
Context.CompleteProducts. .Where(cp => cp.ProductComponent.Any(pc => pc.ProductComponentId == id));
is not even possible and I have to reference through mapping table.

Just wonder if it's possible to "fix" it with out manually change on every mapping.
 internal class ProductComponentProductComponentsProductCompleteProductsCompleteProducts98433873Mapping : EntityTypeConfiguration<ProductComponentProductComponentsProductCompleteProductsCompleteProducts98433873>
    {
        public ProductComponentProductComponentsProductCompleteProductsCompleteProducts98433873Mapping(string schema = "product")
        {
            ToTable(schema + ".ProductComponentProductComponents_product_CompleteProductsCompleteProducts_98433873");
            HasKey(x => x.Oid);

            Property(x => x.CompleteProducts).HasColumnName("CompleteProducts").IsOptional();
            Property(x => x.ProductComponents).HasColumnName("ProductComponents").IsOptional();
            Property(x => x.Oid).HasColumnName("OID").IsRequired().HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
            Property(x => x.OptimisticLockField).HasColumnName("OptimisticLockField").IsOptional();

            // Foreign keys
            HasOptional(a => a.CompleteProducts_CompleteProducts).WithMany(b => b.ProductComponentProductComponentsProductCompleteProductsCompleteProducts98433873).HasForeignKey(c => c.CompleteProducts); // FK_product_ProductComponentProductComponents_product_CompleteProductsCompleteProducts_CompleteProducts_CFAC2A4A
            HasOptional(a => a.ProductComponent).WithMany(b => b.ProductComponentProductComponentsProductCompleteProductsCompleteProducts98433873).HasForeignKey(c => c.ProductComponents); // FK_product_ProductComponentProductComponents_product_CompleteProductsCompleteProducts_ProductComponents_F86E20D6
        }
    }

Viewing all articles
Browse latest Browse all 1642

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>