LinqConnect Documentation
In This Topic
    Creating Configurations
    In This Topic

    The FluentMappingBuilder class implicitly creates configurations for each entity and complex type, registered in it using Entity and ComplexType methods. These configurations are stored in its Configurations collection. You also may add custom explicitly created configurations to this collection.

    All these methods are overloaded, and they can accept both a type that is known at compile time, and a type defined at run-time. Below you can see the example of using these methods:

    builder.Entity<Company>()

    and

    builder.Entity(typeof(Company));
    Type type = Type.GetType("CrmDemoContext.Company")
    builder.Entity(type);

    The following example demonstrates creating mapping for DataContext with two entities, having two associations to each other:

    public partial class CRMDEMODataContext : Devart.Data.Linq.DataContext
    {
        public CRMDEMODataContext() 
          : this(@"Server=Ora;User Id=CRM_DEMO;Password=CRM_DEMO;") {
        }
     
        public CRMDEMODataContext(string connection)
          : base(connection, GetMappingSource(new Devart.Data.Oracle.Linq.Provider.OracleDataProvider())) {
        }
     
        public CRMDEMODataContext(string connection, DataProvider provider)
          : base(connection, GetMappingSource(provider)) {
        }
     
        private static Devart.Data.Linq.Mapping.MappingSource GetMappingSource(DataProvider provider) 
        {
                FluentMappingBuilder builder = new FluentMappingBuilder(provider);
     
                #region Company
     
                builder.Entity<Company>()
                    .FullTableName(@"CRM_DEMO.""Company""")
                    .PrimaryKey(p => p.CompanyID);
                // Properties:
                builder.Entity<Company>()
                    .Property(p => p.CompanyID)
                        .ColumnName(@"""CompanyID""")
                        .ServerDataType(@"NUMBER(9) NOT NULL");
                builder.Entity<Company>()
                    .Property(p => p.CompanyName)
                        .ColumnName(@"""CompanyName""")
                        .NotNullable()
                        .ServerDataType(@"VARCHAR2(40) NOT NULL");
     
                #endregion
     
                #region Order
     
                builder.Entity<Order>()
                    .FullTableName(@"CRM_DEMO.""Orders""")
                    .PrimaryKey(p => p.OrderID);            
                builder.Entity<Order>()
                    .Property(p => p.ShipDate)
                        .ColumnName(@"""ShipDate""")
                        .ServerDataType(@"DATE NULL");
                // Associations:
                builder.Entity<Order>()
                    .Association()
                        .Name(@"Company_Order")
                        .ToOne(order => order.Company).ThisKey(order => order.ShipCompanyID)
                        .FromMany(company => company.Orders).OtherKey(company => company.CompanyID);
                builder.Entity<Order>()
                    .Association()
                        .Name(@"Company_Order1")
                        .ToOne(order => order.Company1).ThisKey(order => order.CompanyID)
                        .FromMany(company => company.Orders1).OtherKey(company => company.CompanyID);
     
                #endregion
     
                return builder.CreateMappingSource();
        }
     
        public Table<Company> Companies;
        public Table<Order> Orders;
    }