One-to-Many Artificial Associations

1 posts, 0 answers
  1. erkan
    erkan avatar
    1 posts
    Member since:
    Jan 2012

    Posted 17 Sep Link to this post

    This is example of One-to-Many Artificial Associations

    public class FluentModelMetadataSource : FluentMetadataSource{protected override IList<MappingConfiguration> PrepareMapping(){List<MappingConfiguration> configurations = new List<MappingConfiguration>();MappingConfiguration<TestClass> testConfiguration = new MappingConfiguration<TestClass>(); testConfiguration.MapType(); testConfiguration.HasProperty( x => x.ID ).IsIdentity();MappingConfiguration productConfiguration = new MappingConfiguration( "Product", "ProductNamespace" ); productConfiguration.HasArtificialPrimitiveProperty<int>( "Id" ).IsIdentity( KeyGenerator.Autoinc ); productConfiguration.HasArtificialStringProperty( "ProductName" ); productConfiguration.HasArtificialPrimitiveProperty<double>( "Price" );MappingConfiguration categoryConfiguration = new MappingConfiguration( "Category", "CategoryNamespace" ); categoryConfiguration.HasArtificialStringProperty( "CategoryName" ); categoryConfiguration.HasArtificialProperty<byte[]>( "Image" ); categoryConfiguration.HasArtificialPrimitiveProperty<int>( "Id" ).IsIdentity( KeyGenerator.Autoinc ); productConfiguration.HasArtificialAssociation( "Category", categoryConfiguration.ConfiguredType ).WithOppositeCollection( "Products" ).ToColumn( "CategoryId" ); categoryConfiguration.HasArtificialCollectionAssociation( "Products", productConfiguration.ConfiguredType ).WithOpposite( "Category" ); configurations.Add( productConfiguration ); configurations.Add( categoryConfiguration ); configurations.Add( testConfiguration );return configurations;}}

     

    var productList= context.GetAll("ProductNamespace.Product").Cast<object>().ToList();

    I get Category values from each records for this but

    var data = context.GetAll("CategoryNamespace.Category").Cast<object>().ToList();

    in this I couldn't get Products that defined as collection in associations. I got this error:

    Ambiguity between 'CategoryNamespace.Category.products' and 'CategoryNamespace.Category.products'

Back to Top