Data Access has been discontinued. Please refer to this page for more information.

Creating The SofiaCarRental Model

This topic will guide you through the process of creating the SofiaCarRental fluent model consumed by the quickstart scenarios in this chapter. The model will utilize the Telerik.DataAccess.Fluent and Telerik.DataAccess.Core NuGet packages and the explicit mapping feature of Telerik Data Access. The next steps will help you implement the model:

The code of the model in this article is available on Visual C# and Visual Basic.

  1. Add a new class library project called SofiaCarRental.Model to your solution.

  2. Integrate the Telerik.DataAccess.Fluent package with the SofiaCarRental.Model project.

    The Telerik.DataAccess.Fluent package depends on the Telerik.DataAccess.Core package, and the latter will be integrated with the SofiaCarRental.Model project as well.

  3. Make sure that the SofiaCarRental sample database is available on a convenient SQL Server instance, and provide the connection string to it in the App.config file of the SofiaCarRental.Model project.

    <connectionStrings>
       <add name="SofiaCarRentalConnection" 
            connectionString="data source=.\sqlexpress;
                              initial catalog=SofiaCarRental_v2.2;
                              integrated security=True" 
            providerName="System.Data.SqlClient" />
    </connectionStrings>
    
  4. Add a new class file to the SofiaCarRental.Model project and name it Car.

  5. From the code snippet on your language of choice (Visual C# or Visual Basic), copy the code for the Car class and paste it in the newly added file.
  6. Do the same for the rest of the persistent classes in the model: Category, Customer, Employee, RentalOrder, and RentalRate.
  7. For the metadatasource of the model, add a new class file to the project, naming it FluentModelMetadataSource, and in it paste the Mapping code.
  8. For the context class, add a new class file named FluentModel, and in it paste the code for both Context and IUnitOfWork.
  9. Save all the files and build the project.

At this point the SofiaCarRental model is ready for consumption.

The SofiaCarRental Model On C#

public partial class Car
{
    private int _carID;
    public virtual int CarID
    {
        get
        {
            return this._carID;
        }
        set
        {
            this._carID = value;
        }
    }

    private string _tagNumber;
    public virtual string TagNumber
    {
        get
        {
            return this._tagNumber;
        }
        set
        {
            this._tagNumber = value;
        }
    }

    private string _make;
    public virtual string Make
    {
        get
        {
            return this._make;
        }
        set
        {
            this._make = value;
        }
    }

    private string _model;
    public virtual string Model
    {
        get
        {
            return this._model;
        }
        set
        {
            this._model = value;
        }
    }

    private short? _carYear;
    public virtual short? CarYear
    {
        get
        {
            return this._carYear;
        }
        set
        {
            this._carYear = value;
        }
    }

    private int? _categoryID;
    public virtual int? CategoryID
    {
        get
        {
            return this._categoryID;
        }
        set
        {
            this._categoryID = value;
        }
    }

    private bool? _mp3Player;
    public virtual bool? Mp3Player
    {
        get
        {
            return this._mp3Player;
        }
        set
        {
            this._mp3Player = value;
        }
    }

    private bool? _dVDPlayer;
    public virtual bool? DVDPlayer
    {
        get
        {
            return this._dVDPlayer;
        }
        set
        {
            this._dVDPlayer = value;
        }
    }

    private bool? _airConditioner;
    public virtual bool? AirConditioner
    {
        get
        {
            return this._airConditioner;
        }
        set
        {
            this._airConditioner = value;
        }
    }

    private bool? _aBS;
    public virtual bool? ABS
    {
        get
        {
            return this._aBS;
        }
        set
        {
            this._aBS = value;
        }
    }

    private bool? _aSR;
    public virtual bool? ASR
    {
        get
        {
            return this._aSR;
        }
        set
        {
            this._aSR = value;
        }
    }

    private bool? _navigation;
    public virtual bool? Navigation
    {
        get
        {
            return this._navigation;
        }
        set
        {
            this._navigation = value;
        }
    }

    private bool? _available;
    public virtual bool? Available
    {
        get
        {
            return this._available;
        }
        set
        {
            this._available = value;
        }
    }

    private double? _latitude;
    public virtual double? Latitude
    {
        get
        {
            return this._latitude;
        }
        set
        {
            this._latitude = value;
        }
    }

    private double? _longitude;
    public virtual double? Longitude
    {
        get
        {
            return this._longitude;
        }
        set
        {
            this._longitude = value;
        }
    }

    private string _imageFileName;
    public virtual string ImageFileName
    {
        get
        {
            return this._imageFileName;
        }
        set
        {
            this._imageFileName = value;
        }
    }

    private decimal? _rating;
    public virtual decimal? Rating
    {
        get
        {
            return this._rating;
        }
        set
        {
            this._rating = value;
        }
    }

    private int? _numberOfRatings;
    public virtual int? NumberOfRatings
    {
        get
        {
            return this._numberOfRatings;
        }
        set
        {
            this._numberOfRatings = value;
        }
    }

    private IList<RentalOrder> _rentalOrders = 
        new List<RentalOrder>();
    public virtual IList<RentalOrder> RentalOrders
    {
        get
        {
            return this._rentalOrders;
        }
    }

    private Category _category;
    public virtual Category Category
    {
        get
        {
            return this._category;
        }
        set
        {
            this._category = value;
        }
    }

}
public partial class Category
{
    private int _categoryID;
    public virtual int CategoryID
    {
        get
        {
            return this._categoryID;
        }
        set
        {
            this._categoryID = value;
        }
    }

    private string _categoryName;
    public virtual string CategoryName
    {
        get
        {
            return this._categoryName;
        }
        set
        {
            this._categoryName = value;
        }
    }

    private string _imageFileName;
    public virtual string ImageFileName
    {
        get
        {
            return this._imageFileName;
        }
        set
        {
            this._imageFileName = value;
        }
    }

    private IList<RentalRate> _rentalRates = 
        new List<RentalRate>();
    public virtual IList<RentalRate> RentalRates
    {
        get
        {
            return this._rentalRates;
        }
    }

    private IList<Car> _cars = new List<Car>();
    public virtual IList<Car> Cars
    {
        get
        {
            return this._cars;
        }
    }

}
public partial class Customer
{
    private int _customerID;
    public virtual int CustomerID
    {
        get
        {
            return this._customerID;
        }
        set
        {
            this._customerID = value;
        }
    }

    private string _drvLicNumber;
    public virtual string DrvLicNumber
    {
        get
        {
            return this._drvLicNumber;
        }
        set
        {
            this._drvLicNumber = value;
        }
    }

    private string _fullName;
    public virtual string FullName
    {
        get
        {
            return this._fullName;
        }
        set
        {
            this._fullName = value;
        }
    }

    private string _address;
    public virtual string Address
    {
        get
        {
            return this._address;
        }
        set
        {
            this._address = value;
        }
    }

    private string _country;
    public virtual string Country
    {
        get
        {
            return this._country;
        }
        set
        {
            this._country = value;
        }
    }

    private string _city;
    public virtual string City
    {
        get
        {
            return this._city;
        }
        set
        {
            this._city = value;
        }
    }

    private string _state;
    public virtual string State
    {
        get
        {
            return this._state;
        }
        set
        {
            this._state = value;
        }
    }

    private string _zIPCode;
    public virtual string ZIPCode
    {
        get
        {
            return this._zIPCode;
        }
        set
        {
            this._zIPCode = value;
        }
    }

    private IList<RentalOrder> _rentalOrders = 
        new List<RentalOrder>();
    public virtual IList<RentalOrder> RentalOrders
    {
        get
        {
            return this._rentalOrders;
        }
    }

}
public partial class Employee
{
    private int _employeeID;
    public virtual int EmployeeID
    {
        get
        {
            return this._employeeID;
        }
        set
        {
            this._employeeID = value;
        }
    }

    private string _employeeNumber;
    public virtual string EmployeeNumber
    {
        get
        {
            return this._employeeNumber;
        }
        set
        {
            this._employeeNumber = value;
        }
    }

    private string _firstName;
    public virtual string FirstName
    {
        get
        {
            return this._firstName;
        }
        set
        {
            this._firstName = value;
        }
    }

    private string _lastName;
    public virtual string LastName
    {
        get
        {
            return this._lastName;
        }
        set
        {
            this._lastName = value;
        }
    }

    private string _fullName;
    public virtual string FullName
    {
        get
        {
            return this._fullName;
        }
        set
        {
            this._fullName = value;
        }
    }

    private string _title;
    public virtual string Title
    {
        get
        {
            return this._title;
        }
        set
        {
            this._title = value;
        }
    }

    private decimal? _hourlySalary;
    public virtual decimal? HourlySalary
    {
        get
        {
            return this._hourlySalary;
        }
        set
        {
            this._hourlySalary = value;
        }
    }

    private IList<RentalOrder> _rentalOrders = 
        new List<RentalOrder>();
    public virtual IList<RentalOrder> RentalOrders
    {
        get
        {
            return this._rentalOrders;
        }
    }

}
public partial class RentalOrder
{
    private int _rentalOrderID;
    public virtual int RentalOrderID
    {
        get
        {
            return this._rentalOrderID;
        }
        set
        {
            this._rentalOrderID = value;
        }
    }

    private DateTime? _dateProcessed;
    public virtual DateTime? DateProcessed
    {
        get
        {
            return this._dateProcessed;
        }
        set
        {
            this._dateProcessed = value;
        }
    }

    private int _employeeID;
    public virtual int EmployeeID
    {
        get
        {
            return this._employeeID;
        }
        set
        {
            this._employeeID = value;
        }
    }

    private int _customerID;
    public virtual int CustomerID
    {
        get
        {
            return this._customerID;
        }
        set
        {
            this._customerID = value;
        }
    }

    private int _carID;
    public virtual int CarID
    {
        get
        {
            return this._carID;
        }
        set
        {
            this._carID = value;
        }
    }

    private string _tankLevel;
    public virtual string TankLevel
    {
        get
        {
            return this._tankLevel;
        }
        set
        {
            this._tankLevel = value;
        }
    }

    private int? _mileageStart;
    public virtual int? MileageStart
    {
        get
        {
            return this._mileageStart;
        }
        set
        {
            this._mileageStart = value;
        }
    }

    private int? _mileageEnd;
    public virtual int? MileageEnd
    {
        get
        {
            return this._mileageEnd;
        }
        set
        {
            this._mileageEnd = value;
        }
    }

    private DateTime _rentStartDate;
    public virtual DateTime RentStartDate
    {
        get
        {
            return this._rentStartDate;
        }
        set
        {
            this._rentStartDate = value;
        }
    }

    private DateTime _rentEndDate;
    public virtual DateTime RentEndDate
    {
        get
        {
            return this._rentEndDate;
        }
        set
        {
            this._rentEndDate = value;
        }
    }

    private int? _days;
    public virtual int? Days
    {
        get
        {
            return this._days;
        }
        set
        {
            this._days = value;
        }
    }

    private decimal? _rateApplied;
    public virtual decimal? RateApplied
    {
        get
        {
            return this._rateApplied;
        }
        set
        {
            this._rateApplied = value;
        }
    }

    private decimal? _orderTotal;
    public virtual decimal? OrderTotal
    {
        get
        {
            return this._orderTotal;
        }
        set
        {
            this._orderTotal = value;
        }
    }

    private string _orderStatus;
    public virtual string OrderStatus
    {
        get
        {
            return this._orderStatus;
        }
        set
        {
            this._orderStatus = value;
        }
    }

    private Car _car;
    public virtual Car Car
    {
        get
        {
            return this._car;
        }
        set
        {
            this._car = value;
        }
    }

    private Customer _customer;
    public virtual Customer Customer
    {
        get
        {
            return this._customer;
        }
        set
        {
            this._customer = value;
        }
    }

    private Employee _employee;
    public virtual Employee Employee
    {
        get
        {
            return this._employee;
        }
        set
        {
            this._employee = value;
        }
    }

}
public partial class RentalRate
{
    private int _rentalRateID;
    public virtual int RentalRateID
    {
        get
        {
            return this._rentalRateID;
        }
        set
        {
            this._rentalRateID = value;
        }
    }

    private int? _categoryID;
    public virtual int? CategoryID
    {
        get
        {
            return this._categoryID;
        }
        set
        {
            this._categoryID = value;
        }
    }

    private decimal? _daily;
    public virtual decimal? Daily
    {
        get
        {
            return this._daily;
        }
        set
        {
            this._daily = value;
        }
    }

    private decimal? _weekly;
    public virtual decimal? Weekly
    {
        get
        {
            return this._weekly;
        }
        set
        {
            this._weekly = value;
        }
    }

    private decimal? _monthly;
    public virtual decimal? Monthly
    {
        get
        {
            return this._monthly;
        }
        set
        {
            this._monthly = value;
        }
    }

    private Category _category;
    public virtual Category Category
    {
        get
        {
            return this._category;
        }
        set
        {
            this._category = value;
        }
    }

}
public partial class FluentModelMetadataSource : FluentMetadataSource
{

    protected override IList<MappingConfiguration> PrepareMapping()
    {
        List<MappingConfiguration> mappingConfigurations = 
            new List<MappingConfiguration>();

        MappingConfiguration<RentalRate> rentalrateConfiguration = 
            this.GetRentalRateMappingConfiguration();
        mappingConfigurations.Add(rentalrateConfiguration);

        MappingConfiguration<RentalOrder> rentalorderConfiguration = 
            this.GetRentalOrderMappingConfiguration();
        mappingConfigurations.Add(rentalorderConfiguration);

        MappingConfiguration<Employee> employeeConfiguration = 
            this.GetEmployeeMappingConfiguration();
        mappingConfigurations.Add(employeeConfiguration);

        MappingConfiguration<Customer> customerConfiguration = 
            this.GetCustomerMappingConfiguration();
        mappingConfigurations.Add(customerConfiguration);

        MappingConfiguration<Category> categoryConfiguration = 
            this.GetCategoryMappingConfiguration();
        mappingConfigurations.Add(categoryConfiguration);

        MappingConfiguration<Car> carConfiguration = 
            this.GetCarMappingConfiguration();
        mappingConfigurations.Add(carConfiguration);

        return mappingConfigurations;
    }

    protected override void SetContainerSettings
        (MetadataContainer container)
    {
        container.Name = "FluentModel";
        container.DefaultNamespace = "SofiaCarRentalModel";
        container.NameGenerator.SourceStrategy = 
            Telerik.OpenAccess.Metadata.NamingSourceStrategy.Property;
        container.NameGenerator.RemoveCamelCase = false;
    }
    public MappingConfiguration<RentalRate> 
        GetRentalRateMappingConfiguration()
    {
        MappingConfiguration<RentalRate> configuration = 
            this.GetRentalRateClassConfiguration();
        this.PrepareRentalRatePropertyConfigurations(configuration);
        this.PrepareRentalRateAssociationConfigurations(configuration);

        return configuration;
    }

    public MappingConfiguration<RentalRate> 
        GetRentalRateClassConfiguration()
    {
        MappingConfiguration<RentalRate> configuration = 
            new MappingConfiguration<RentalRate>();
        configuration.
            MapType(x => new { }).
            WithConcurencyControl(OptimisticConcurrencyControlStrategy.
                Changed).
            ToTable("RentalRates");

        return configuration;
    }

    public void PrepareRentalRatePropertyConfigurations
        (MappingConfiguration<RentalRate> configuration)
    {
        configuration.HasProperty(x => x.RentalRateID).
            IsIdentity(KeyGenerator.Autoinc).
            HasFieldName("_rentalRateID").
            WithDataAccessKind(DataAccessKind.ReadWrite).
            ToColumn("RentalRateID").IsNotNullable().
            HasColumnType("int").HasPrecision(0).HasScale(0);
        configuration.HasProperty(x => x.CategoryID).
            HasFieldName("_categoryID").
            WithDataAccessKind(DataAccessKind.ReadWrite).
            ToColumn("CategoryID").IsNullable().
            HasColumnType("int").HasPrecision(0).HasScale(0);
        configuration.HasProperty(x => x.Daily).
            HasFieldName("_daily").
            WithDataAccessKind(DataAccessKind.ReadWrite).
            ToColumn("Daily").IsNullable().
            HasColumnType("smallmoney").HasPrecision(0).HasScale(0);
        configuration.HasProperty(x => x.Weekly).
            HasFieldName("_weekly").
            WithDataAccessKind(DataAccessKind.ReadWrite).
            ToColumn("Weekly").IsNullable().
            HasColumnType("smallmoney").HasPrecision(0).HasScale(0);
        configuration.HasProperty(x => x.Monthly).
            HasFieldName("_monthly").
            WithDataAccessKind(DataAccessKind.ReadWrite).
            ToColumn("Monthly").IsNullable().
            HasColumnType("smallmoney").HasPrecision(0).HasScale(0);
    }

    public void PrepareRentalRateAssociationConfigurations
        (MappingConfiguration<RentalRate> configuration)
    {
        configuration.HasAssociation(x => x.Category).
            HasFieldName("_category").WithOpposite(x => x.RentalRates).
            ToColumn("CategoryID").
            HasConstraint((x, y) =>  x.CategoryID == y.CategoryID ).
            WithDataAccessKind(DataAccessKind.ReadWrite);
    }

    public MappingConfiguration<RentalOrder> 
        GetRentalOrderMappingConfiguration()
    {
        MappingConfiguration<RentalOrder> configuration = 
            this.GetRentalOrderClassConfiguration();
        this.PrepareRentalOrderPropertyConfigurations(configuration);
        this.PrepareRentalOrderAssociationConfigurations(configuration);

        return configuration;
    }

    public MappingConfiguration<RentalOrder> 
        GetRentalOrderClassConfiguration()
    {
        MappingConfiguration<RentalOrder> configuration = 
            new MappingConfiguration<RentalOrder>();
        configuration.
            MapType(x => new { }).
            WithConcurencyControl(OptimisticConcurrencyControlStrategy.
                Changed)
            .ToTable("RentalOrders");

        return configuration;
    }

    public void PrepareRentalOrderPropertyConfigurations
        (MappingConfiguration<RentalOrder> configuration)
    {
        configuration.HasProperty(x => x.RentalOrderID).
            IsIdentity(KeyGenerator.Autoinc).
            HasFieldName("_rentalOrderID").
            WithDataAccessKind(DataAccessKind.ReadWrite).
            ToColumn("RentalOrderID").IsNotNullable().
            HasColumnType("int").HasPrecision(0).HasScale(0);
        configuration.HasProperty(x => x.DateProcessed).
            HasFieldName("_dateProcessed").
            WithDataAccessKind(DataAccessKind.ReadWrite).
            ToColumn("DateProcessed").IsNullable().
            HasColumnType("datetime");
        configuration.HasProperty(x => x.EmployeeID).
            HasFieldName("_employeeID").
            WithDataAccessKind(DataAccessKind.ReadWrite).
            ToColumn("EmployeeID").IsNotNullable().
            HasColumnType("int").HasPrecision(0).HasScale(0);
        configuration.HasProperty(x => x.CustomerID).
            HasFieldName("_customerID").
            WithDataAccessKind(DataAccessKind.ReadWrite).
            ToColumn("CustomerID").IsNotNullable().
            HasColumnType("int").HasPrecision(0).HasScale(0);
        configuration.HasProperty(x => x.CarID).
            HasFieldName("_carID").
            WithDataAccessKind(DataAccessKind.ReadWrite).
            ToColumn("CarID").IsNotNullable().
            HasColumnType("int").HasPrecision(0).HasScale(0);
        configuration.HasProperty(x => x.TankLevel).
            HasFieldName("_tankLevel").
            WithDataAccessKind(DataAccessKind.ReadWrite).
            ToColumn("TankLevel").IsNullable().
            HasColumnType("varchar").HasLength(40);
        configuration.HasProperty(x => x.MileageStart).
            HasFieldName("_mileageStart").
            WithDataAccessKind(DataAccessKind.ReadWrite).
            ToColumn("MileageStart").IsNullable().
            HasColumnType("int").HasPrecision(0).HasScale(0);
        configuration.HasProperty(x => x.MileageEnd).
            HasFieldName("_mileageEnd").
            WithDataAccessKind(DataAccessKind.ReadWrite).
            ToColumn("MileageEnd").IsNullable().
            HasColumnType("int").HasPrecision(0).HasScale(0);
        configuration.HasProperty(x => x.RentStartDate).
            HasFieldName("_rentStartDate").
            WithDataAccessKind(DataAccessKind.ReadWrite).
            ToColumn("RentStartDate").IsNotNullable().
            HasColumnType("datetime");
        configuration.HasProperty(x => x.RentEndDate).
            HasFieldName("_rentEndDate").
            WithDataAccessKind(DataAccessKind.ReadWrite).
            ToColumn("RentEndDate").IsNotNullable().
            HasColumnType("datetime");
        configuration.HasProperty(x => x.Days).
            HasFieldName("_days").
            WithDataAccessKind(DataAccessKind.ReadOnly).
            ToColumn("Days").IsNullable().
            HasColumnType("int").HasPrecision(0).HasScale(0);
        configuration.HasProperty(x => x.RateApplied).
            HasFieldName("_rateApplied").
            WithDataAccessKind(DataAccessKind.ReadWrite).
            ToColumn("RateApplied").IsNullable().
            HasColumnType("money").HasPrecision(0).HasScale(0);
        configuration.HasProperty(x => x.OrderTotal).
            HasFieldName("_orderTotal").
            WithDataAccessKind(DataAccessKind.ReadOnly).
            ToColumn("OrderTotal").IsNullable().
            HasColumnType("money").HasPrecision(0).HasScale(0);
        configuration.HasProperty(x => x.OrderStatus).
            HasFieldName("_orderStatus").
            WithDataAccessKind(DataAccessKind.ReadWrite).
            ToColumn("OrderStatus").IsNullable().
            HasColumnType("varchar").HasLength(50);
    }

    public void PrepareRentalOrderAssociationConfigurations
        (MappingConfiguration<RentalOrder> configuration)
    {
        configuration.HasAssociation(x => x.Car).
            HasFieldName("_car").WithOpposite(x => x.RentalOrders).
            ToColumn("CarID").
            HasConstraint((x, y) =>  x.CarID == y.CarID ).
            IsRequired().WithDataAccessKind(DataAccessKind.ReadWrite);
        configuration.HasAssociation(x => x.Customer).
            HasFieldName("_customer").WithOpposite(x => x.RentalOrders).
            ToColumn("CustomerID").
            HasConstraint((x, y) =>  x.CustomerID == y.CustomerID ).
            IsRequired().WithDataAccessKind(DataAccessKind.ReadWrite);
        configuration.HasAssociation(x => x.Employee).
            HasFieldName("_employee").
            WithOpposite(x => x.RentalOrders).
            ToColumn("EmployeeID").
            HasConstraint((x, y) =>  x.EmployeeID == y.EmployeeID ).
            IsRequired().WithDataAccessKind(DataAccessKind.ReadWrite);
    }

    public MappingConfiguration<Employee> 
        GetEmployeeMappingConfiguration()
    {
        MappingConfiguration<Employee> configuration = 
            this.GetEmployeeClassConfiguration();
        this.PrepareEmployeePropertyConfigurations(configuration);
        this.PrepareEmployeeAssociationConfigurations(configuration);

        return configuration;
    }

    public MappingConfiguration<Employee> 
        GetEmployeeClassConfiguration()
    {
        MappingConfiguration<Employee> configuration = 
            new MappingConfiguration<Employee>();
        configuration.
            MapType(x => new { }).
            WithConcurencyControl(OptimisticConcurrencyControlStrategy.
                Changed).
            ToTable("Employees");

        return configuration;
    }

    public void PrepareEmployeePropertyConfigurations
        (MappingConfiguration<Employee> configuration)
    {
        configuration.HasProperty(x => x.EmployeeID).
            IsIdentity(KeyGenerator.Autoinc).
            HasFieldName("_employeeID").
            WithDataAccessKind(DataAccessKind.ReadWrite).
            ToColumn("EmployeeID").IsNotNullable().
            HasColumnType("int").HasPrecision(0).HasScale(0);
        configuration.HasProperty(x => x.EmployeeNumber).
            HasFieldName("_employeeNumber").
            WithDataAccessKind(DataAccessKind.ReadWrite).
            ToColumn("EmployeeNumber").IsNullable().
            HasColumnType("nchar").HasLength(5);
        configuration.HasProperty(x => x.FirstName).
            HasFieldName("_firstName").
            WithDataAccessKind(DataAccessKind.ReadWrite).
            ToColumn("FirstName").IsNullable().
            HasColumnType("varchar").HasLength(32);
        configuration.HasProperty(x => x.LastName).
            HasFieldName("_lastName").
            WithDataAccessKind(DataAccessKind.ReadWrite).
            ToColumn("LastName").IsNotNullable().
            HasColumnType("varchar").HasLength(32);
        configuration.HasProperty(x => x.FullName).
            HasFieldName("_fullName").
            WithDataAccessKind(DataAccessKind.ReadWrite).
            ToColumn("FullName").IsNullable().
            HasColumnType("varchar").HasLength(66);
        configuration.HasProperty(x => x.Title).
            HasFieldName("_title").
            WithDataAccessKind(DataAccessKind.ReadWrite).
            ToColumn("Title").IsNullable().
            HasColumnType("varchar").HasLength(80);
        configuration.HasProperty(x => x.HourlySalary).
            HasFieldName("_hourlySalary").
            WithDataAccessKind(DataAccessKind.ReadWrite).
            ToColumn("HourlySalary").IsNullable().
            HasColumnType("smallmoney").HasPrecision(0).HasScale(0);
    }

    public void PrepareEmployeeAssociationConfigurations
        (MappingConfiguration<Employee> configuration)
    {
        configuration.HasAssociation(x => x.RentalOrders).
            HasFieldName("_rentalOrders").
            WithOpposite(x => x.Employee).ToColumn("EmployeeID").
            HasConstraint((y, x) =>  x.EmployeeID == y.EmployeeID ).
            WithDataAccessKind(DataAccessKind.ReadWrite);
    }

    public MappingConfiguration<Customer> 
        GetCustomerMappingConfiguration()
    {
        MappingConfiguration<Customer> configuration = 
            this.GetCustomerClassConfiguration();
        this.PrepareCustomerPropertyConfigurations(configuration);
        this.PrepareCustomerAssociationConfigurations(configuration);

        return configuration;
    }

    public MappingConfiguration<Customer> 
        GetCustomerClassConfiguration()
    {
        MappingConfiguration<Customer> configuration = 
            new MappingConfiguration<Customer>();
        configuration.
            MapType(x => new { }).
            WithConcurencyControl(OptimisticConcurrencyControlStrategy.
                Changed).
            ToTable("Customers");

        return configuration;
    }

    public void PrepareCustomerPropertyConfigurations
        (MappingConfiguration<Customer> configuration)
    {
        configuration.HasProperty(x => x.CustomerID).
            IsIdentity(KeyGenerator.Autoinc).
            HasFieldName("_customerID").
            WithDataAccessKind(DataAccessKind.ReadWrite).
            ToColumn("CustomerID").IsNotNullable().
            HasColumnType("int").HasPrecision(0).HasScale(0);
        configuration.HasProperty(x => x.DrvLicNumber).
            HasFieldName("_drvLicNumber").
            WithDataAccessKind(DataAccessKind.ReadWrite).
            ToColumn("DrvLicNumber").IsNullable().
            HasColumnType("varchar").HasLength(50);
        configuration.HasProperty(x => x.FullName).
            HasFieldName("_fullName").
            WithDataAccessKind(DataAccessKind.ReadWrite).
            ToColumn("FullName").IsNullable().
            HasColumnType("varchar").HasLength(80);
        configuration.HasProperty(x => x.Address).
            HasFieldName("_address").
            WithDataAccessKind(DataAccessKind.ReadWrite).
            ToColumn("Address").IsNotNullable().
            HasColumnType("varchar").HasLength(100);
        configuration.HasProperty(x => x.Country).
            HasFieldName("_country").
            WithDataAccessKind(DataAccessKind.ReadWrite).
            ToColumn("Country").IsNotNullable().
            HasColumnType("varchar").HasLength(100);
        configuration.HasProperty(x => x.City).
            HasFieldName("_city").
            WithDataAccessKind(DataAccessKind.ReadWrite).
            ToColumn("City").IsNullable().
            HasColumnType("varchar").HasLength(50);
        configuration.HasProperty(x => x.State).
            HasFieldName("_state").
            WithDataAccessKind(DataAccessKind.ReadWrite).
            ToColumn("State").IsNullable().
            HasColumnType("varchar").HasLength(50);
        configuration.HasProperty(x => x.ZIPCode).
            HasFieldName("_zIPCode").
            WithDataAccessKind(DataAccessKind.ReadWrite).
            ToColumn("ZIPCode").IsNullable().
            HasColumnType("varchar").HasLength(20);
    }

    public void PrepareCustomerAssociationConfigurations
        (MappingConfiguration<Customer> configuration)
    {
        configuration.HasAssociation(x => x.RentalOrders).
            HasFieldName("_rentalOrders").
            WithOpposite(x => x.Customer).ToColumn("CustomerID").
            HasConstraint((y, x) =>  x.CustomerID == y.CustomerID ).
            WithDataAccessKind(DataAccessKind.ReadWrite);
    }

    public MappingConfiguration<Category> 
        GetCategoryMappingConfiguration()
    {
        MappingConfiguration<Category> configuration = 
            this.GetCategoryClassConfiguration();
        this.PrepareCategoryPropertyConfigurations(configuration);
        this.PrepareCategoryAssociationConfigurations(configuration);

        return configuration;
    }

    public MappingConfiguration<Category> 
        GetCategoryClassConfiguration()
    {
        MappingConfiguration<Category> configuration = 
            new MappingConfiguration<Category>();
        configuration.
            MapType(x => new { }).
            WithConcurencyControl(OptimisticConcurrencyControlStrategy.
                Changed).
            ToTable("Categories");

        return configuration;
    }

    public void PrepareCategoryPropertyConfigurations
        (MappingConfiguration<Category> configuration)
    {
        configuration.HasProperty(x => x.CategoryID).
            IsIdentity(KeyGenerator.Autoinc).
            HasFieldName("_categoryID").
            WithDataAccessKind(DataAccessKind.ReadWrite).
            ToColumn("CategoryID").IsNotNullable().
            HasColumnType("int").HasPrecision(0).HasScale(0);
        configuration.HasProperty(x => x.CategoryName).
            HasFieldName("_categoryName").
            WithDataAccessKind(DataAccessKind.ReadWrite).
            ToColumn("CategoryName").IsNotNullable().
            HasColumnType("varchar").HasLength(50);
        configuration.HasProperty(x => x.ImageFileName).
            HasFieldName("_imageFileName").
            WithDataAccessKind(DataAccessKind.ReadWrite).
            ToColumn("ImageFileName").IsNullable().
            HasColumnType("varchar").HasLength(256).HasDefaultValue();
    }

    public void PrepareCategoryAssociationConfigurations
        (MappingConfiguration<Category> configuration)
    {
        configuration.HasAssociation(x => x.RentalRates).
            HasFieldName("_rentalRates").
            WithOpposite(x => x.Category).ToColumn("CategoryID").
            HasConstraint((y, x) =>  x.CategoryID == y.CategoryID ).
            WithDataAccessKind(DataAccessKind.ReadWrite);
        configuration.HasAssociation(x => x.Cars).
            HasFieldName("_cars").
            WithOpposite(x => x.Category).ToColumn("CategoryID").
            HasConstraint((y, x) =>  x.CategoryID == y.CategoryID ).
            WithDataAccessKind(DataAccessKind.ReadWrite);
    }

    public MappingConfiguration<Car> GetCarMappingConfiguration()
    {
        MappingConfiguration<Car> configuration = 
            this.GetCarClassConfiguration();
        this.PrepareCarPropertyConfigurations(configuration);
        this.PrepareCarAssociationConfigurations(configuration);

        return configuration;
    }

    public MappingConfiguration<Car> GetCarClassConfiguration()
    {
        MappingConfiguration<Car> configuration = 
            new MappingConfiguration<Car>();
        configuration.
            MapType(x => new { }).
            WithConcurencyControl(OptimisticConcurrencyControlStrategy.
                Changed).
            ToTable("Cars");

        return configuration;
    }

    public void PrepareCarPropertyConfigurations
        (MappingConfiguration<Car> configuration)
    {
        configuration.HasProperty(x => x.CarID).
            IsIdentity(KeyGenerator.Autoinc).
            HasFieldName("_carID").
            WithDataAccessKind(DataAccessKind.ReadWrite).
            ToColumn("CarID").IsNotNullable().
            HasColumnType("int").HasPrecision(0).HasScale(0);
        configuration.HasProperty(x => x.TagNumber).
            HasFieldName("_tagNumber").
            WithDataAccessKind(DataAccessKind.ReadWrite).
            ToColumn("TagNumber").IsNotNullable().
            HasColumnType("varchar").HasLength(20);
        configuration.HasProperty(x => x.Make).
            HasFieldName("_make").
            WithDataAccessKind(DataAccessKind.ReadWrite).
            ToColumn("Make").IsNullable().
            HasColumnType("varchar").HasLength(50);
        configuration.HasProperty(x => x.Model).
            HasFieldName("_model").
            WithDataAccessKind(DataAccessKind.ReadWrite).
            ToColumn("Model").IsNotNullable().
            HasColumnType("varchar").HasLength(50);
        configuration.HasProperty(x => x.CarYear).
            HasFieldName("_carYear").
            WithDataAccessKind(DataAccessKind.ReadWrite).
            ToColumn("CarYear").IsNullable().
            HasColumnType("smallint").HasPrecision(0).HasScale(0);
        configuration.HasProperty(x => x.CategoryID).
            HasFieldName("_categoryID").
            WithDataAccessKind(DataAccessKind.ReadWrite).
            ToColumn("CategoryID").IsNullable().
            HasColumnType("int").HasPrecision(0).HasScale(0);
        configuration.HasProperty(x => x.Mp3Player).
            HasFieldName("_mp3Player").
            WithDataAccessKind(DataAccessKind.ReadWrite).
            ToColumn("Mp3Player").IsNullable().
            HasColumnType("bit").HasPrecision(0).HasScale(0);
        configuration.HasProperty(x => x.DVDPlayer).
            HasFieldName("_dVDPlayer").
            WithDataAccessKind(DataAccessKind.ReadWrite).
            ToColumn("DVDPlayer").IsNullable().
            HasColumnType("bit").HasPrecision(0).HasScale(0);
        configuration.HasProperty(x => x.AirConditioner).
            HasFieldName("_airConditioner").
            WithDataAccessKind(DataAccessKind.ReadWrite).
            ToColumn("AirConditioner").IsNullable().
            HasColumnType("bit").HasPrecision(0).HasScale(0);
        configuration.HasProperty(x => x.ABS).
            HasFieldName("_aBS").
            WithDataAccessKind(DataAccessKind.ReadWrite).
            ToColumn("ABS").IsNullable().
            HasColumnType("bit").HasPrecision(0).HasScale(0);
        configuration.HasProperty(x => x.ASR).
            HasFieldName("_aSR").
            WithDataAccessKind(DataAccessKind.ReadWrite).
            ToColumn("ASR").IsNullable().
            HasColumnType("bit").HasPrecision(0).HasScale(0);
        configuration.HasProperty(x => x.Navigation).
            HasFieldName("_navigation").
            WithDataAccessKind(DataAccessKind.ReadWrite).
            ToColumn("Navigation").IsNullable().
            HasColumnType("bit").HasPrecision(0).HasScale(0);
        configuration.HasProperty(x => x.Available).
            HasFieldName("_available").
            WithDataAccessKind(DataAccessKind.ReadWrite).
            ToColumn("Available").IsNullable().
            HasColumnType("bit").HasPrecision(0).HasScale(0);
        configuration.HasProperty(x => x.Latitude).
            HasFieldName("_latitude").
            WithDataAccessKind(DataAccessKind.ReadWrite).
            ToColumn("Latitude").IsNullable().
            HasColumnType("float").HasPrecision(0).
            HasScale(0).HasDefaultValue();
        configuration.HasProperty(x => x.Longitude).
            HasFieldName("_longitude").
            WithDataAccessKind(DataAccessKind.ReadWrite).
            ToColumn("Longitude").IsNullable().
            HasColumnType("float").HasPrecision(0).HasScale(0).
            HasDefaultValue();
        configuration.HasProperty(x => x.ImageFileName).
            HasFieldName("_imageFileName").
            WithDataAccessKind(DataAccessKind.ReadWrite).
            ToColumn("ImageFileName").IsNullable().
            HasColumnType("varchar").HasLength(256).HasDefaultValue();
        configuration.HasProperty(x => x.Rating).
            HasFieldName("_rating").
            WithDataAccessKind(DataAccessKind.ReadWrite).
            ToColumn("Rating").IsNullable().
            HasColumnType("decimal").
            HasPrecision(9).HasScale(2).HasDefaultValue();
        configuration.HasProperty(x => x.NumberOfRatings).
            HasFieldName("_numberOfRatings").
            WithDataAccessKind(DataAccessKind.ReadWrite).
            ToColumn("NumberOfRatings").IsNullable().
            HasColumnType("int").HasPrecision(0).HasScale(0).
            HasDefaultValue();
    }

    public void PrepareCarAssociationConfigurations
        (MappingConfiguration<Car> configuration)
    {
        configuration.HasAssociation(x => x.RentalOrders).
            HasFieldName("_rentalOrders").
            WithOpposite(x => x.Car).ToColumn("CarID").
            HasConstraint((y, x) =>  x.CarID == y.CarID ).
            WithDataAccessKind(DataAccessKind.ReadWrite);
        configuration.HasAssociation(x => x.Category).
            HasFieldName("_category").
            WithOpposite(x => x.Cars).ToColumn("CategoryID").
            HasConstraint((x, y) =>  x.CategoryID == y.CategoryID ).
            WithDataAccessKind(DataAccessKind.ReadWrite);
    }
}
public partial class FluentModel : OpenAccessContext, IFluentModelUnitOfWork
{
    private static string connectionStringName = @"SofiaCarRentalConnection";

    private static BackendConfiguration backend = GetBackendConfiguration();

    private static MetadataSource metadataSource = 
        new FluentModelMetadataSource();

    public FluentModel()
        :base(connectionStringName, backend, metadataSource)
    { }

    public FluentModel(string connection)
        :base(connection, backend, metadataSource)
    { }

    public FluentModel(BackendConfiguration backendConfiguration)
        :base(connectionStringName, backendConfiguration, metadataSource)
    { }

    public FluentModel(string connection, MetadataSource metadataSource)
        :base(connection, backend, metadataSource)
    { }

    public FluentModel(string connection, 
                       BackendConfiguration backendConfiguration, 
                       MetadataSource metadataSource)
        :base(connection, backendConfiguration, metadataSource)
    { }

    public IQueryable<RentalRate> RentalRates 
    {
        get
        {
            return this.GetAll<RentalRate>();
        }
    }

    public IQueryable<RentalOrder> RentalOrders 
    {
        get
        {
            return this.GetAll<RentalOrder>();
        }
    }

    public IQueryable<Employee> Employees 
    {
        get
        {
            return this.GetAll<Employee>();
        }
    }

    public IQueryable<Customer> Customers 
    {
        get
        {
            return this.GetAll<Customer>();
        }
    }

    public IQueryable<Category> Categories 
    {
        get
        {
            return this.GetAll<Category>();
        }
    }

    public IQueryable<Car> Cars 
    {
        get
        {
            return this.GetAll<Car>();
        }
    }

    public static BackendConfiguration GetBackendConfiguration()
    {
        BackendConfiguration backend = new BackendConfiguration();
        backend.Backend = "MsSql";
        backend.ProviderName = "System.Data.SqlClient";

        CustomizeBackendConfiguration(ref backend);

        return backend;
    }

    /// <summary>
    /// Allows you to customize the BackendConfiguration of FluentModel.
    /// </summary>
    /// <param name="config">The BackendConfiguration of FluentModel.</param>
    static partial void CustomizeBackendConfiguration
        (ref BackendConfiguration config);

}
public interface IFluentModelUnitOfWork : IUnitOfWork
{
    IQueryable<RentalRate> RentalRates
    {
        get;
    }
    IQueryable<RentalOrder> RentalOrders
    {
        get;
    }
    IQueryable<Employee> Employees
    {
        get;
    }
    IQueryable<Customer> Customers
    {
        get;
    }
    IQueryable<Category> Categories
    {
        get;
    }
    IQueryable<Car> Cars
    {
        get;
    }
}

The SofiaCarRental On VB

Public Partial Class Car
    Private _carID As Integer 
    Public Overridable Property CarID As Integer
        Get
            Return Me._carID
        End Get
        Set(ByVal value As Integer)
            Me._carID = value
        End Set
    End Property

    Private _tagNumber As String 
    Public Overridable Property TagNumber As String
        Get
            Return Me._tagNumber
        End Get
        Set(ByVal value As String)
            Me._tagNumber = value
        End Set
    End Property

    Private _make As String 
    Public Overridable Property Make As String
        Get
            Return Me._make
        End Get
        Set(ByVal value As String)
            Me._make = value
        End Set
    End Property

    Private _model As String 
    Public Overridable Property Model As String
        Get
            Return Me._model
        End Get
        Set(ByVal value As String)
            Me._model = value
        End Set
    End Property

    Private _carYear As Short? 
    Public Overridable Property CarYear As Short?
        Get
            Return Me._carYear
        End Get
        Set(ByVal value As Short?)
            Me._carYear = value
        End Set
    End Property

    Private _categoryID As Integer? 
    Public Overridable Property CategoryID As Integer?
        Get
            Return Me._categoryID
        End Get
        Set(ByVal value As Integer?)
            Me._categoryID = value
        End Set
    End Property

    Private _mp3Player As Boolean? 
    Public Overridable Property Mp3Player As Boolean?
        Get
            Return Me._mp3Player
        End Get
        Set(ByVal value As Boolean?)
            Me._mp3Player = value
        End Set
    End Property

    Private _dVDPlayer As Boolean? 
    Public Overridable Property DVDPlayer As Boolean?
        Get
            Return Me._dVDPlayer
        End Get
        Set(ByVal value As Boolean?)
            Me._dVDPlayer = value
        End Set
    End Property

    Private _airConditioner As Boolean? 
    Public Overridable Property AirConditioner As Boolean?
        Get
            Return Me._airConditioner
        End Get
        Set(ByVal value As Boolean?)
            Me._airConditioner = value
        End Set
    End Property

    Private _aBS As Boolean? 
    Public Overridable Property ABS As Boolean?
        Get
            Return Me._aBS
        End Get
        Set(ByVal value As Boolean?)
            Me._aBS = value
        End Set
    End Property

    Private _aSR As Boolean? 
    Public Overridable Property ASR As Boolean?
        Get
            Return Me._aSR
        End Get
        Set(ByVal value As Boolean?)
            Me._aSR = value
        End Set
    End Property

    Private _navigation As Boolean? 
    Public Overridable Property Navigation As Boolean?
        Get
            Return Me._navigation
        End Get
        Set(ByVal value As Boolean?)
            Me._navigation = value
        End Set
    End Property

    Private _available As Boolean? 
    Public Overridable Property Available As Boolean?
        Get
            Return Me._available
        End Get
        Set(ByVal value As Boolean?)
            Me._available = value
        End Set
    End Property

    Private _latitude As Double? 
    Public Overridable Property Latitude As Double?
        Get
            Return Me._latitude
        End Get
        Set(ByVal value As Double?)
            Me._latitude = value
        End Set
    End Property

    Private _longitude As Double? 
    Public Overridable Property Longitude As Double?
        Get
            Return Me._longitude
        End Get
        Set(ByVal value As Double?)
            Me._longitude = value
        End Set
    End Property

    Private _imageFileName As String 
    Public Overridable Property ImageFileName As String
        Get
            Return Me._imageFileName
        End Get
        Set(ByVal value As String)
            Me._imageFileName = value
        End Set
    End Property

    Private _rating As Decimal? 
    Public Overridable Property Rating As Decimal?
        Get
            Return Me._rating
        End Get
        Set(ByVal value As Decimal?)
            Me._rating = value
        End Set
    End Property

    Private _numberOfRatings As Integer? 
    Public Overridable Property NumberOfRatings As Integer?
        Get
            Return Me._numberOfRatings
        End Get
        Set(ByVal value As Integer?)
            Me._numberOfRatings = value
        End Set
    End Property

    Private _rentalOrders As IList(Of RentalOrder)  = 
        new List(Of RentalOrder)
    Public Overridable ReadOnly Property RentalOrders _
        As IList(Of RentalOrder)
        Get
            Return Me._rentalOrders
        End Get
    End Property

    Private _category As Category 
    Public Overridable Property Category As Category
        Get
            Return Me._category
        End Get
        Set(ByVal value As Category)
            Me._category = value
        End Set
    End Property

End Class
Public Partial Class Category
    Private _categoryID As Integer 
    Public Overridable Property CategoryID As Integer
        Get
            Return Me._categoryID
        End Get
        Set(ByVal value As Integer)
            Me._categoryID = value
        End Set
    End Property

    Private _categoryName As String 
    Public Overridable Property CategoryName As String
        Get
            Return Me._categoryName
        End Get
        Set(ByVal value As String)
            Me._categoryName = value
        End Set
    End Property

    Private _imageFileName As String 
    Public Overridable Property ImageFileName As String
        Get
            Return Me._imageFileName
        End Get
        Set(ByVal value As String)
            Me._imageFileName = value
        End Set
    End Property

    Private _rentalRates As IList(Of RentalRate)  = 
        new List(Of RentalRate)
    Public Overridable ReadOnly Property RentalRates _
        As IList(Of RentalRate)
        Get
            Return Me._rentalRates
        End Get
    End Property

    Private _cars As IList(Of Car)  = new List(Of Car)
    Public Overridable ReadOnly Property Cars As IList(Of Car)
        Get
            Return Me._cars
        End Get
    End Property

End Class
Public Partial Class Customer
    Private _customerID As Integer 
    Public Overridable Property CustomerID As Integer
        Get
            Return Me._customerID
        End Get
        Set(ByVal value As Integer)
            Me._customerID = value
        End Set
    End Property

    Private _drvLicNumber As String 
    Public Overridable Property DrvLicNumber As String
        Get
            Return Me._drvLicNumber
        End Get
        Set(ByVal value As String)
            Me._drvLicNumber = value
        End Set
    End Property

    Private _fullName As String 
    Public Overridable Property FullName As String
        Get
            Return Me._fullName
        End Get
        Set(ByVal value As String)
            Me._fullName = value
        End Set
    End Property

    Private _address As String 
    Public Overridable Property Address As String
        Get
            Return Me._address
        End Get
        Set(ByVal value As String)
            Me._address = value
        End Set
    End Property

    Private _country As String 
    Public Overridable Property Country As String
        Get
            Return Me._country
        End Get
        Set(ByVal value As String)
            Me._country = value
        End Set
    End Property

    Private _city As String 
    Public Overridable Property City As String
        Get
            Return Me._city
        End Get
        Set(ByVal value As String)
            Me._city = value
        End Set
    End Property

    Private _state As String 
    Public Overridable Property State As String
        Get
            Return Me._state
        End Get
        Set(ByVal value As String)
            Me._state = value
        End Set
    End Property

    Private _zIPCode As String 
    Public Overridable Property ZIPCode As String
        Get
            Return Me._zIPCode
        End Get
        Set(ByVal value As String)
            Me._zIPCode = value
        End Set
    End Property

    Private _rentalOrders As IList(Of RentalOrder)  = 
        new List(Of RentalOrder)
    Public Overridable ReadOnly Property RentalOrders _
        As IList(Of RentalOrder)
        Get
            Return Me._rentalOrders
        End Get
    End Property

End Class
Public Partial Class Employee
    Private _employeeID As Integer 
    Public Overridable Property EmployeeID As Integer
        Get
            Return Me._employeeID
        End Get
        Set(ByVal value As Integer)
            Me._employeeID = value
        End Set
    End Property

    Private _employeeNumber As String 
    Public Overridable Property EmployeeNumber As String
        Get
            Return Me._employeeNumber
        End Get
        Set(ByVal value As String)
            Me._employeeNumber = value
        End Set
    End Property

    Private _firstName As String 
    Public Overridable Property FirstName As String
        Get
            Return Me._firstName
        End Get
        Set(ByVal value As String)
            Me._firstName = value
        End Set
    End Property

    Private _lastName As String 
    Public Overridable Property LastName As String
        Get
            Return Me._lastName
        End Get
        Set(ByVal value As String)
            Me._lastName = value
        End Set
    End Property

    Private _fullName As String 
    Public Overridable Property FullName As String
        Get
            Return Me._fullName
        End Get
        Set(ByVal value As String)
            Me._fullName = value
        End Set
    End Property

    Private _title As String 
    Public Overridable Property Title As String
        Get
            Return Me._title
        End Get
        Set(ByVal value As String)
            Me._title = value
        End Set
    End Property

    Private _hourlySalary As Decimal? 
    Public Overridable Property HourlySalary As Decimal?
        Get
            Return Me._hourlySalary
        End Get
        Set(ByVal value As Decimal?)
            Me._hourlySalary = value
        End Set
    End Property

    Private _rentalOrders As IList(Of RentalOrder)  = 
        new List(Of RentalOrder)
    Public Overridable ReadOnly Property RentalOrders _
        As IList(Of RentalOrder)
        Get
            Return Me._rentalOrders
        End Get
    End Property

End Class
Public Partial Class RentalOrder
    Private _rentalOrderID As Integer 
    Public Overridable Property RentalOrderID As Integer
        Get
            Return Me._rentalOrderID
        End Get
        Set(ByVal value As Integer)
            Me._rentalOrderID = value
        End Set
    End Property

    Private _dateProcessed As Date? 
    Public Overridable Property DateProcessed As Date?
        Get
            Return Me._dateProcessed
        End Get
        Set(ByVal value As Date?)
            Me._dateProcessed = value
        End Set
    End Property

    Private _employeeID As Integer 
    Public Overridable Property EmployeeID As Integer
        Get
            Return Me._employeeID
        End Get
        Set(ByVal value As Integer)
            Me._employeeID = value
        End Set
    End Property

    Private _customerID As Integer 
    Public Overridable Property CustomerID As Integer
        Get
            Return Me._customerID
        End Get
        Set(ByVal value As Integer)
            Me._customerID = value
        End Set
    End Property

    Private _carID As Integer 
    Public Overridable Property CarID As Integer
        Get
            Return Me._carID
        End Get
        Set(ByVal value As Integer)
            Me._carID = value
        End Set
    End Property

    Private _tankLevel As String 
    Public Overridable Property TankLevel As String
        Get
            Return Me._tankLevel
        End Get
        Set(ByVal value As String)
            Me._tankLevel = value
        End Set
    End Property

    Private _mileageStart As Integer? 
    Public Overridable Property MileageStart As Integer?
        Get
            Return Me._mileageStart
        End Get
        Set(ByVal value As Integer?)
            Me._mileageStart = value
        End Set
    End Property

    Private _mileageEnd As Integer? 
    Public Overridable Property MileageEnd As Integer?
        Get
            Return Me._mileageEnd
        End Get
        Set(ByVal value As Integer?)
            Me._mileageEnd = value
        End Set
    End Property

    Private _rentStartDate As Date 
    Public Overridable Property RentStartDate As Date
        Get
            Return Me._rentStartDate
        End Get
        Set(ByVal value As Date)
            Me._rentStartDate = value
        End Set
    End Property

    Private _rentEndDate As Date 
    Public Overridable Property RentEndDate As Date
        Get
            Return Me._rentEndDate
        End Get
        Set(ByVal value As Date)
            Me._rentEndDate = value
        End Set
    End Property

    Private _days As Integer? 
    Public Overridable Property Days As Integer?
        Get
            Return Me._days
        End Get
        Set(ByVal value As Integer?)
            Me._days = value
        End Set
    End Property

    Private _rateApplied As Decimal? 
    Public Overridable Property RateApplied As Decimal?
        Get
            Return Me._rateApplied
        End Get
        Set(ByVal value As Decimal?)
            Me._rateApplied = value
        End Set
    End Property

    Private _orderTotal As Decimal? 
    Public Overridable Property OrderTotal As Decimal?
        Get
            Return Me._orderTotal
        End Get
        Set(ByVal value As Decimal?)
            Me._orderTotal = value
        End Set
    End Property

    Private _orderStatus As String 
    Public Overridable Property OrderStatus As String
        Get
            Return Me._orderStatus
        End Get
        Set(ByVal value As String)
            Me._orderStatus = value
        End Set
    End Property

    Private _car As Car 
    Public Overridable Property Car As Car
        Get
            Return Me._car
        End Get
        Set(ByVal value As Car)
            Me._car = value
        End Set
    End Property

    Private _customer As Customer 
    Public Overridable Property Customer As Customer
        Get
            Return Me._customer
        End Get
        Set(ByVal value As Customer)
            Me._customer = value
        End Set
    End Property

    Private _employee As Employee 
    Public Overridable Property Employee As Employee
        Get
            Return Me._employee
        End Get
        Set(ByVal value As Employee)
            Me._employee = value
        End Set
    End Property

End Class
Public Partial Class RentalRate
    Private _rentalRateID As Integer 
    Public Overridable Property RentalRateID As Integer
        Get
            Return Me._rentalRateID
        End Get
        Set(ByVal value As Integer)
            Me._rentalRateID = value
        End Set
    End Property

    Private _categoryID As Integer? 
    Public Overridable Property CategoryID As Integer?
        Get
            Return Me._categoryID
        End Get
        Set(ByVal value As Integer?)
            Me._categoryID = value
        End Set
    End Property

    Private _daily As Decimal? 
    Public Overridable Property Daily As Decimal?
        Get
            Return Me._daily
        End Get
        Set(ByVal value As Decimal?)
            Me._daily = value
        End Set
    End Property

    Private _weekly As Decimal? 
    Public Overridable Property Weekly As Decimal?
        Get
            Return Me._weekly
        End Get
        Set(ByVal value As Decimal?)
            Me._weekly = value
        End Set
    End Property

    Private _monthly As Decimal? 
    Public Overridable Property Monthly As Decimal?
        Get
            Return Me._monthly
        End Get
        Set(ByVal value As Decimal?)
            Me._monthly = value
        End Set
    End Property

    Private _category As Category 
    Public Overridable Property Category As Category
        Get
            Return Me._category
        End Get
        Set(ByVal value As Category)
            Me._category = value
        End Set
    End Property

End Class
Partial Public Class FluentModelMetadataSource
    Inherits FluentMetadataSource

    Protected Overrides Function PrepareMapping() _
        As IList(Of MappingConfiguration)
        Dim mappingConfigurations _
            As New List(Of MappingConfiguration)()
        Dim rentalrateConfiguration _
            As MappingConfiguration(Of RentalRate) =
            Me.GetRentalRateMappingConfiguration()
        mappingConfigurations.Add(rentalrateConfiguration)

        Dim rentalorderConfiguration _
            As MappingConfiguration(Of RentalOrder) =
            Me.GetRentalOrderMappingConfiguration()
        mappingConfigurations.Add(rentalorderConfiguration)

        Dim employeeConfiguration _
            As MappingConfiguration(Of Employee) =
            Me.GetEmployeeMappingConfiguration()
        mappingConfigurations.Add(employeeConfiguration)

        Dim customerConfiguration _
            As MappingConfiguration(Of Customer) =
            Me.GetCustomerMappingConfiguration()
        mappingConfigurations.Add(customerConfiguration)

        Dim categoryConfiguration _
            As MappingConfiguration(Of Category) =
            Me.GetCategoryMappingConfiguration()
        mappingConfigurations.Add(categoryConfiguration)

        Dim carConfiguration _
            As MappingConfiguration(Of Car) =
            Me.GetCarMappingConfiguration()
        mappingConfigurations.Add(carConfiguration)

        Return mappingConfigurations
    End Function

    Protected Overrides Sub SetContainerSettings(container _
        As MetadataContainer)
        container.Name = "FluentModel"
        container.DefaultNamespace = "SofiaCarRentalModel.VB"
        container.RootNamespace = "SofiaCarRentalModel.VB"
        container.NameGenerator.SourceStrategy =
            Telerik.OpenAccess.Metadata.NamingSourceStrategy.Property
        container.NameGenerator.RemoveCamelCase = False
    End Sub
    Public Function GetRentalRateMappingConfiguration() _
        As MappingConfiguration(Of RentalRate)
        Dim configuration As MappingConfiguration(Of RentalRate) =
            Me.GetRentalRateClassConfiguration()
        Me.PrepareRentalRatePropertyConfigurations(configuration)
        Me.PrepareRentalRateAssociationConfigurations(configuration)

        Return configuration
    End Function

    Public Function GetRentalRateClassConfiguration() _
        As MappingConfiguration(Of RentalRate)
        Dim configuration As New MappingConfiguration(Of RentalRate)()
        configuration.
            MapType(Function(x) New With {x}).
            WithConcurencyControl(OptimisticConcurrencyControlStrategy.
                                  Changed).
            ToTable("RentalRates")

        Return configuration
    End Function

    Public Sub PrepareRentalRatePropertyConfigurations(configuration _
        As MappingConfiguration(Of RentalRate))
        configuration.HasProperty(Function(x) x.RentalRateID).
            IsIdentity(KeyGenerator.Autoinc).
            HasFieldName("_rentalRateID").
            WithDataAccessKind(DataAccessKind.ReadWrite).
            ToColumn("RentalRateID").IsNotNullable().
            HasColumnType("int").HasPrecision(0).HasScale(0)
        configuration.HasProperty(Function(x) x.CategoryID).
            HasFieldName("_categoryID").
            WithDataAccessKind(DataAccessKind.ReadWrite).
            ToColumn("CategoryID").IsNullable().
            HasColumnType("int").HasPrecision(0).HasScale(0)
        configuration.HasProperty(Function(x) x.Daily).
            HasFieldName("_daily").
            WithDataAccessKind(DataAccessKind.ReadWrite).
            ToColumn("Daily").IsNullable().
            HasColumnType("smallmoney").HasPrecision(0).HasScale(0)
        configuration.HasProperty(Function(x) x.Weekly).
            HasFieldName("_weekly").
            WithDataAccessKind(DataAccessKind.ReadWrite).
            ToColumn("Weekly").IsNullable().
            HasColumnType("smallmoney").HasPrecision(0).HasScale(0)
        configuration.HasProperty(Function(x) x.Monthly).
            HasFieldName("_monthly").
            WithDataAccessKind(DataAccessKind.ReadWrite).
            ToColumn("Monthly").IsNullable().
            HasColumnType("smallmoney").HasPrecision(0).HasScale(0)
    End Sub

    Public Sub PrepareRentalRateAssociationConfigurations(configuration _
        As MappingConfiguration(Of RentalRate))
        configuration.HasAssociation(Function(x) x.Category).
            HasFieldName("_category").
            WithOpposite(Function(x) x.RentalRates).
            ToColumn("CategoryID").
            HasConstraint(Function(x, y) x.CategoryID = y.CategoryID).
            WithDataAccessKind(DataAccessKind.ReadWrite)
    End Sub

    Public Function GetRentalOrderMappingConfiguration() _
        As MappingConfiguration(Of RentalOrder)
        Dim configuration As MappingConfiguration(Of RentalOrder) =
            Me.GetRentalOrderClassConfiguration()
        Me.PrepareRentalOrderPropertyConfigurations(configuration)
        Me.PrepareRentalOrderAssociationConfigurations(configuration)

        Return configuration
    End Function

    Public Function GetRentalOrderClassConfiguration() _
        As MappingConfiguration(Of RentalOrder)
        Dim configuration As New MappingConfiguration(Of RentalOrder)()
        configuration.
            MapType(Function(x) New With {x}).
            WithConcurencyControl(OptimisticConcurrencyControlStrategy.
                Changed).
            ToTable("RentalOrders")

        Return configuration
    End Function

    Public Sub PrepareRentalOrderPropertyConfigurations(configuration _
        As MappingConfiguration(Of RentalOrder))
        configuration.HasProperty(Function(x) x.RentalOrderID).
            IsIdentity(KeyGenerator.Autoinc).
            HasFieldName("_rentalOrderID").
            WithDataAccessKind(DataAccessKind.ReadWrite).
            ToColumn("RentalOrderID").IsNotNullable().
            HasColumnType("int").HasPrecision(0).HasScale(0)
        configuration.HasProperty(Function(x) x.DateProcessed).
            HasFieldName("_dateProcessed").
            WithDataAccessKind(DataAccessKind.ReadWrite).
            ToColumn("DateProcessed").IsNullable().HasColumnType("datetime")
        configuration.HasProperty(Function(x) x.EmployeeID).
            HasFieldName("_employeeID").
            WithDataAccessKind(DataAccessKind.ReadWrite).
            ToColumn("EmployeeID").IsNotNullable().
            HasColumnType("int").HasPrecision(0).HasScale(0)
        configuration.HasProperty(Function(x) x.CustomerID).
            HasFieldName("_customerID").
            WithDataAccessKind(DataAccessKind.ReadWrite).
            ToColumn("CustomerID").IsNotNullable().
            HasColumnType("int").HasPrecision(0).HasScale(0)
        configuration.HasProperty(Function(x) x.CarID).
            HasFieldName("_carID").
            WithDataAccessKind(DataAccessKind.ReadWrite).
            ToColumn("CarID").IsNotNullable().
            HasColumnType("int").HasPrecision(0).HasScale(0)
        configuration.HasProperty(Function(x) x.TankLevel).
            HasFieldName("_tankLevel").
            WithDataAccessKind(DataAccessKind.ReadWrite).
            ToColumn("TankLevel").IsNullable().
            HasColumnType("varchar").HasLength(40)
        configuration.HasProperty(Function(x) x.MileageStart).
            HasFieldName("_mileageStart").
            WithDataAccessKind(DataAccessKind.ReadWrite).
            ToColumn("MileageStart").IsNullable().
            HasColumnType("int").HasPrecision(0).HasScale(0)
        configuration.HasProperty(Function(x) x.MileageEnd).
            HasFieldName("_mileageEnd").
            WithDataAccessKind(DataAccessKind.ReadWrite).
            ToColumn("MileageEnd").IsNullable().
            HasColumnType("int").HasPrecision(0).HasScale(0)
        configuration.HasProperty(Function(x) x.RentStartDate).
            HasFieldName("_rentStartDate").
            WithDataAccessKind(DataAccessKind.ReadWrite).
            ToColumn("RentStartDate").IsNotNullable().
            HasColumnType("datetime")
        configuration.HasProperty(Function(x) x.RentEndDate).
            HasFieldName("_rentEndDate").
            WithDataAccessKind(DataAccessKind.ReadWrite).
            ToColumn("RentEndDate").IsNotNullable().
            HasColumnType("datetime")
        configuration.HasProperty(Function(x) x.Days).
            HasFieldName("_days").
            WithDataAccessKind(DataAccessKind.ReadOnly).
            ToColumn("Days").IsNullable().
            HasColumnType("int").HasPrecision(0).HasScale(0)
        configuration.HasProperty(Function(x) x.RateApplied).
            HasFieldName("_rateApplied").
            WithDataAccessKind(DataAccessKind.ReadWrite).
            ToColumn("RateApplied").IsNullable().
            HasColumnType("money").HasPrecision(0).HasScale(0)
        configuration.HasProperty(Function(x) x.OrderTotal).
            HasFieldName("_orderTotal").
            WithDataAccessKind(DataAccessKind.ReadOnly).
            ToColumn("OrderTotal").IsNullable().
            HasColumnType("money").HasPrecision(0).HasScale(0)
        configuration.HasProperty(Function(x) x.OrderStatus).
            HasFieldName("_orderStatus").
            WithDataAccessKind(DataAccessKind.ReadWrite).
            ToColumn("OrderStatus").IsNullable().
            HasColumnType("varchar").HasLength(50)
    End Sub

    Public Sub PrepareRentalOrderAssociationConfigurations(configuration _
        As MappingConfiguration(Of RentalOrder))
        configuration.HasAssociation(Function(x) x.Car).
            HasFieldName("_car").
            WithOpposite(Function(x) x.RentalOrders).
            ToColumn("CarID").
            HasConstraint(Function(x, y) x.CarID = y.CarID).
            IsRequired().WithDataAccessKind(DataAccessKind.ReadWrite)
        configuration.HasAssociation(Function(x) x.Customer).
            HasFieldName("_customer").
            WithOpposite(Function(x) x.RentalOrders).
            ToColumn("CustomerID").
            HasConstraint(Function(x, y) x.CustomerID = y.CustomerID).
            IsRequired().WithDataAccessKind(DataAccessKind.ReadWrite)
        configuration.HasAssociation(Function(x) x.Employee).
            HasFieldName("_employee").
            WithOpposite(Function(x) x.RentalOrders).
            ToColumn("EmployeeID").
            HasConstraint(Function(x, y) x.EmployeeID = y.EmployeeID).
            IsRequired().WithDataAccessKind(DataAccessKind.ReadWrite)
    End Sub

    Public Function GetEmployeeMappingConfiguration() _
        As MappingConfiguration(Of Employee)
        Dim configuration As MappingConfiguration(Of Employee) =
            Me.GetEmployeeClassConfiguration()
        Me.PrepareEmployeePropertyConfigurations(configuration)
        Me.PrepareEmployeeAssociationConfigurations(configuration)

        Return configuration
    End Function

    Public Function GetEmployeeClassConfiguration() _
        As MappingConfiguration(Of Employee)
        Dim configuration As New MappingConfiguration(Of Employee)()
        configuration.
            MapType(Function(x) New With {x}).
            WithConcurencyControl(OptimisticConcurrencyControlStrategy.
                Changed).
            ToTable("Employees")

        Return configuration
    End Function

    Public Sub PrepareEmployeePropertyConfigurations(configuration _
        As MappingConfiguration(Of Employee))
        configuration.HasProperty(Function(x) x.EmployeeID).
            IsIdentity(KeyGenerator.Autoinc).
            HasFieldName("_employeeID").
            WithDataAccessKind(DataAccessKind.ReadWrite).
            ToColumn("EmployeeID").IsNotNullable().
            HasColumnType("int").HasPrecision(0).HasScale(0)
        configuration.HasProperty(Function(x) x.EmployeeNumber).
            HasFieldName("_employeeNumber").
            WithDataAccessKind(DataAccessKind.ReadWrite).
            ToColumn("EmployeeNumber").IsNullable().
            HasColumnType("nchar").HasLength(5)
        configuration.HasProperty(Function(x) x.FirstName).
            HasFieldName("_firstName").
            WithDataAccessKind(DataAccessKind.ReadWrite).
            ToColumn("FirstName").IsNullable().
            HasColumnType("varchar").HasLength(32)
        configuration.HasProperty(Function(x) x.LastName).
            HasFieldName("_lastName").
            WithDataAccessKind(DataAccessKind.ReadWrite).
            ToColumn("LastName").IsNotNullable().
            HasColumnType("varchar").HasLength(32)
        configuration.HasProperty(Function(x) x.FullName).
            HasFieldName("_fullName").
            WithDataAccessKind(DataAccessKind.ReadWrite).
            ToColumn("FullName").IsNullable().
            HasColumnType("varchar").HasLength(66)
        configuration.HasProperty(Function(x) x.Title).
            HasFieldName("_title").
            WithDataAccessKind(DataAccessKind.ReadWrite).
            ToColumn("Title").IsNullable().
            HasColumnType("varchar").HasLength(80)
        configuration.HasProperty(Function(x) x.HourlySalary).
            HasFieldName("_hourlySalary").
            WithDataAccessKind(DataAccessKind.ReadWrite).
            ToColumn("HourlySalary").IsNullable().
            HasColumnType("smallmoney").HasPrecision(0).HasScale(0)
    End Sub

    Public Sub PrepareEmployeeAssociationConfigurations(configuration _
        As MappingConfiguration(Of Employee))
        configuration.
            HasAssociation(Of RentalOrder)(Function(x) x.RentalOrders).
            HasFieldName("_rentalOrders").
            WithOpposite(Function(x) x.Employee).
            ToColumn("EmployeeID").
            HasConstraint(Function(y, x) x.EmployeeID = y.EmployeeID).
            WithDataAccessKind(DataAccessKind.ReadWrite)
    End Sub

    Public Function GetCustomerMappingConfiguration() _
        As MappingConfiguration(Of Customer)
        Dim configuration As MappingConfiguration(Of Customer) =
            Me.GetCustomerClassConfiguration()
        Me.PrepareCustomerPropertyConfigurations(configuration)
        Me.PrepareCustomerAssociationConfigurations(configuration)

        Return configuration
    End Function

    Public Function GetCustomerClassConfiguration() _
        As MappingConfiguration(Of Customer)
        Dim configuration As New MappingConfiguration(Of Customer)()
        configuration.
            MapType(Function(x) New With {x}).
            WithConcurencyControl(OptimisticConcurrencyControlStrategy.
                Changed).
            ToTable("Customers")

        Return configuration
    End Function

    Public Sub PrepareCustomerPropertyConfigurations(configuration _
        As MappingConfiguration(Of Customer))
        configuration.HasProperty(Function(x) x.CustomerID).
            IsIdentity(KeyGenerator.Autoinc).
            HasFieldName("_customerID").
            WithDataAccessKind(DataAccessKind.ReadWrite).
            ToColumn("CustomerID").IsNotNullable().
            HasColumnType("int").HasPrecision(0).HasScale(0)
        configuration.HasProperty(Function(x) x.DrvLicNumber).
            HasFieldName("_drvLicNumber").
            WithDataAccessKind(DataAccessKind.ReadWrite).
            ToColumn("DrvLicNumber").IsNullable().
            HasColumnType("varchar").HasLength(50)
        configuration.HasProperty(Function(x) x.FullName).
            HasFieldName("_fullName").
            WithDataAccessKind(DataAccessKind.ReadWrite).
            ToColumn("FullName").IsNullable().
            HasColumnType("varchar").HasLength(80)
        configuration.HasProperty(Function(x) x.Address).
            HasFieldName("_address").
            WithDataAccessKind(DataAccessKind.ReadWrite).
            ToColumn("Address").IsNotNullable().
            HasColumnType("varchar").HasLength(100)
        configuration.HasProperty(Function(x) x.Country).
            HasFieldName("_country").
            WithDataAccessKind(DataAccessKind.ReadWrite).
            ToColumn("Country").IsNotNullable().
            HasColumnType("varchar").HasLength(100)
        configuration.HasProperty(Function(x) x.City).
            HasFieldName("_city").
            WithDataAccessKind(DataAccessKind.ReadWrite).
            ToColumn("City").IsNullable().
            HasColumnType("varchar").HasLength(50)
        configuration.HasProperty(Function(x) x.State).
            HasFieldName("_state").
            WithDataAccessKind(DataAccessKind.ReadWrite).
            ToColumn("State").IsNullable().
            HasColumnType("varchar").HasLength(50)
        configuration.HasProperty(Function(x) x.ZIPCode).
            HasFieldName("_zIPCode").
            WithDataAccessKind(DataAccessKind.ReadWrite).
            ToColumn("ZIPCode").IsNullable().
            HasColumnType("varchar").HasLength(20)
    End Sub

    Public Sub PrepareCustomerAssociationConfigurations(configuration _
        As MappingConfiguration(Of Customer))
        configuration.
            HasAssociation(Of RentalOrder)(Function(x) x.RentalOrders).
            HasFieldName("_rentalOrders").
            WithOpposite(Function(x) x.Customer).
            ToColumn("CustomerID").
            HasConstraint(Function(y, x) x.CustomerID = y.CustomerID).
            WithDataAccessKind(DataAccessKind.ReadWrite)
    End Sub

    Public Function GetCategoryMappingConfiguration() _
        As MappingConfiguration(Of Category)
        Dim configuration As MappingConfiguration(Of Category) =
            Me.GetCategoryClassConfiguration()
        Me.PrepareCategoryPropertyConfigurations(configuration)
        Me.PrepareCategoryAssociationConfigurations(configuration)

        Return configuration
    End Function

    Public Function GetCategoryClassConfiguration() _
        As MappingConfiguration(Of Category)
        Dim configuration As New MappingConfiguration(Of Category)()
        configuration.
            MapType(Function(x) New With {x}).
            WithConcurencyControl(OptimisticConcurrencyControlStrategy.
                Changed).
            ToTable("Categories")

        Return configuration
    End Function

    Public Sub PrepareCategoryPropertyConfigurations(configuration _
        As MappingConfiguration(Of Category))
        configuration.HasProperty(Function(x) x.CategoryID).
            IsIdentity(KeyGenerator.Autoinc).
            HasFieldName("_categoryID").
            WithDataAccessKind(DataAccessKind.ReadWrite).
            ToColumn("CategoryID").IsNotNullable().
            HasColumnType("int").HasPrecision(0).HasScale(0)
        configuration.HasProperty(Function(x) x.CategoryName).
            HasFieldName("_categoryName").
            WithDataAccessKind(DataAccessKind.ReadWrite).
            ToColumn("CategoryName").IsNotNullable().
            HasColumnType("varchar").HasLength(50)
        configuration.HasProperty(Function(x) x.ImageFileName).
            HasFieldName("_imageFileName").
            WithDataAccessKind(DataAccessKind.ReadWrite).
            ToColumn("ImageFileName").IsNullable().
            HasColumnType("varchar").HasLength(256).HasDefaultValue()
    End Sub

    Public Sub PrepareCategoryAssociationConfigurations(configuration _
        As MappingConfiguration(Of Category))
        configuration.
            HasAssociation(Of RentalRate)(Function(x) x.RentalRates).
            HasFieldName("_rentalRates").
            WithOpposite(Function(x) x.Category).
            ToColumn("CategoryID").
            HasConstraint(Function(y, x) x.CategoryID = y.CategoryID).
            WithDataAccessKind(DataAccessKind.ReadWrite)
        configuration.
            HasAssociation(Of Car)(Function(x) x.Cars).
            HasFieldName("_cars").
            WithOpposite(Function(x) x.Category).
            ToColumn("CategoryID").
            HasConstraint(Function(y, x) x.CategoryID = y.CategoryID).
            WithDataAccessKind(DataAccessKind.ReadWrite)
    End Sub

    Public Function GetCarMappingConfiguration() _
        As MappingConfiguration(Of Car)
        Dim configuration As MappingConfiguration(Of Car) =
            Me.GetCarClassConfiguration()
        Me.PrepareCarPropertyConfigurations(configuration)
        Me.PrepareCarAssociationConfigurations(configuration)

        Return configuration
    End Function

    Public Function GetCarClassConfiguration() _
        As MappingConfiguration(Of Car)
        Dim configuration As New MappingConfiguration(Of Car)()
        configuration.
            MapType(Function(x) New With {x}).
            WithConcurencyControl(OptimisticConcurrencyControlStrategy.
                Changed).
            ToTable("Cars")

        Return configuration
    End Function

    Public Sub PrepareCarPropertyConfigurations(configuration _
        As MappingConfiguration(Of Car))
        configuration().
            HasProperty(Function(x) x.CarID).
            IsIdentity(KeyGenerator.Autoinc).
            HasFieldName("_carID").
            WithDataAccessKind(DataAccessKind.ReadWrite).
            ToColumn("CarID").IsNotNullable().
            HasColumnType("int").HasPrecision(0).HasScale(0)
        configuration.HasProperty(Function(x) x.TagNumber).
            HasFieldName("_tagNumber").
            WithDataAccessKind(DataAccessKind.ReadWrite).
            ToColumn("TagNumber").IsNotNullable().
            HasColumnType("varchar").HasLength(20)
        configuration.HasProperty(Function(x) x.Make).
            HasFieldName("_make").
            WithDataAccessKind(DataAccessKind.ReadWrite).
            ToColumn("Make").IsNullable().
            HasColumnType("varchar").HasLength(50)
        configuration.HasProperty(Function(x) x.Model).
            HasFieldName("_model").
            WithDataAccessKind(DataAccessKind.ReadWrite).
            ToColumn("Model").IsNotNullable().
            HasColumnType("varchar").HasLength(50)
        configuration.HasProperty(Function(x) x.CarYear).
            HasFieldName("_carYear").
            WithDataAccessKind(DataAccessKind.ReadWrite).
            ToColumn("CarYear").IsNullable().
            HasColumnType("smallint").HasPrecision(0).HasScale(0)
        configuration.HasProperty(Function(x) x.CategoryID).
            HasFieldName("_categoryID").
            WithDataAccessKind(DataAccessKind.ReadWrite).
            ToColumn("CategoryID").IsNullable().
            HasColumnType("int").HasPrecision(0).HasScale(0)
        configuration.HasProperty(Function(x) x.Mp3Player).
            HasFieldName("_mp3Player").
            WithDataAccessKind(DataAccessKind.ReadWrite).
            ToColumn("Mp3Player").IsNullable().
            HasColumnType("bit").HasPrecision(0).HasScale(0)
        configuration.HasProperty(Function(x) x.DVDPlayer).
            HasFieldName("_dVDPlayer").
            WithDataAccessKind(DataAccessKind.ReadWrite).
            ToColumn("DVDPlayer").IsNullable().
            HasColumnType("bit").HasPrecision(0).HasScale(0)
        configuration.HasProperty(Function(x) x.AirConditioner).
            HasFieldName("_airConditioner").
            WithDataAccessKind(DataAccessKind.ReadWrite).
            ToColumn("AirConditioner").IsNullable().
            HasColumnType("bit").HasPrecision(0).HasScale(0)
        configuration.HasProperty(Function(x) x.ABS).
            HasFieldName("_aBS").
            WithDataAccessKind(DataAccessKind.ReadWrite).
            ToColumn("ABS").IsNullable().
            HasColumnType("bit").HasPrecision(0).HasScale(0)
        configuration.HasProperty(Function(x) x.ASR).
            HasFieldName("_aSR").
            WithDataAccessKind(DataAccessKind.ReadWrite).
            ToColumn("ASR").IsNullable().
            HasColumnType("bit").HasPrecision(0).HasScale(0)
        configuration.HasProperty(Function(x) x.Navigation).
            HasFieldName("_navigation").
            WithDataAccessKind(DataAccessKind.ReadWrite).
            ToColumn("Navigation").IsNullable().
            HasColumnType("bit").HasPrecision(0).HasScale(0)
        configuration.HasProperty(Function(x) x.Available).
            HasFieldName("_available").
            WithDataAccessKind(DataAccessKind.ReadWrite).
            ToColumn("Available").IsNullable().
            HasColumnType("bit").HasPrecision(0).HasScale(0)
        configuration.HasProperty(Function(x) x.Latitude).
            HasFieldName("_latitude").
            WithDataAccessKind(DataAccessKind.ReadWrite).
            ToColumn("Latitude").IsNullable().
            HasColumnType("float").HasPrecision(0).
            HasScale(0).HasDefaultValue()
        configuration.HasProperty(Function(x) x.Longitude).
            HasFieldName("_longitude").
            WithDataAccessKind(DataAccessKind.ReadWrite).
            ToColumn("Longitude").IsNullable().
            HasColumnType("float").HasPrecision(0).
            HasScale(0).HasDefaultValue()
        configuration.HasProperty(Function(x) x.ImageFileName).
            HasFieldName("_imageFileName").
            WithDataAccessKind(DataAccessKind.ReadWrite).
            ToColumn("ImageFileName").IsNullable().
            HasColumnType("varchar").HasLength(256).HasDefaultValue()
        configuration.HasProperty(Function(x) x.Rating).
            HasFieldName("_rating").
            WithDataAccessKind(DataAccessKind.ReadWrite).
            ToColumn("Rating").IsNullable().
            HasColumnType("decimal").HasPrecision(9).
            HasScale(2).HasDefaultValue()
        configuration.HasProperty(Function(x) x.NumberOfRatings).
            HasFieldName("_numberOfRatings").
            WithDataAccessKind(DataAccessKind.ReadWrite).
            ToColumn("NumberOfRatings").IsNullable().
            HasColumnType("int").HasPrecision(0).
            HasScale(0).HasDefaultValue()
    End Sub

    Public Sub PrepareCarAssociationConfigurations(configuration _
        As MappingConfiguration(Of Car))
        configuration.
            HasAssociation(Of RentalOrder)(Function(x) x.RentalOrders).
            HasFieldName("_rentalOrders").
            WithOpposite(Function(x) x.Car).ToColumn("CarID").
            HasConstraint(Function(y, x) x.CarID = y.CarID).
            WithDataAccessKind(DataAccessKind.ReadWrite)
        configuration.HasAssociation(Function(x) x.Category).
            HasFieldName("_category").
            WithOpposite(Function(x) x.Cars).ToColumn("CategoryID").
            HasConstraint(Function(x, y) x.CategoryID = y.CategoryID).
            WithDataAccessKind(DataAccessKind.ReadWrite)
    End Sub
End Class
Public Partial Class FluentModel
    Inherits OpenAccessContext
    Implements IFluentModelUnitOfWork
    Private Shared connectionStringName As String =
        "SofiaCarRentalConnection"

    Private Shared backend As BackendConfiguration =
        GetBackendConfiguration()

    Private Shared metadataSource As MetadataSource =
        New FluentModelMetadataSource()

    Public Sub New()
        MyBase.New(connectionStringName, backend, metadataSource)
    End Sub

    Public Sub New(ByVal connection As String)
        MyBase.New(connection, backend, metadataSource)
    End Sub

    Public Sub New(ByVal backendConfiguration As BackendConfiguration)
        MyBase.New(connectionStringName,
                   backendConfiguration,
                   metadataSource)
    End Sub

    Public Sub New(ByVal connection As String,
                   ByVal metadataSource As MetadataSource)
        MyBase.New(connection, backend, metadataSource)
    End Sub

    Public Sub New(ByVal connection As String,
                   ByVal backendConfiguration As BackendConfiguration,
                   ByVal metadataSource As MetadataSource)
        MyBase.New(connection, backendConfiguration, metadataSource)
    End Sub

    Public ReadOnly Property RentalRates() As IQueryable(Of RentalRate) _
        Implements IFluentModelUnitOfWork.RentalRates
        Get
            Return Me.GetAll(Of RentalRate)()
        End Get
    End Property

    Public ReadOnly Property RentalOrders() As IQueryable(Of RentalOrder) _
        Implements IFluentModelUnitOfWork.RentalOrders
        Get
            Return Me.GetAll(Of RentalOrder)()
        End Get
    End Property

    Public ReadOnly Property Employees() As IQueryable(Of Employee) _
        Implements IFluentModelUnitOfWork.Employees
        Get
            Return Me.GetAll(Of Employee)()
        End Get
    End Property

    Public ReadOnly Property Customers() As IQueryable(Of Customer) _
        Implements IFluentModelUnitOfWork.Customers
        Get
            Return Me.GetAll(Of Customer)()
        End Get
    End Property

    Public ReadOnly Property Categories() As IQueryable(Of Category) _
        Implements IFluentModelUnitOfWork.Categories
        Get
            Return Me.GetAll(Of Category)()
        End Get
    End Property

    Public ReadOnly Property Cars() As IQueryable(Of Car) _
        Implements IFluentModelUnitOfWork.Cars
        Get
            Return Me.GetAll(Of Car)()
        End Get
    End Property

    Public Sub Reroute_Add(entity As Object) _
        Implements IUnitOfWork.Add
        Me.Add(entity)
    End Sub

    Public Sub Reroute_ClearChanges() _
        Implements IUnitOfWork.ClearChanges
        Me.ClearChanges()
    End Sub

    Public Sub Reroute_Delete(entity As Object) _
        Implements IUnitOfWork.Delete
        Me.Delete(entity)
    End Sub

    Public Function Reroute_GetAll(Of T)() As IQueryable(Of T) _
        Implements IUnitOfWork.GetAll
        Return Me.GetAll(Of T)()
    End Function

    Public Function Reroute_GetObjectByKey(Of T)(key _
        As Telerik.OpenAccess.ObjectKey) As T _
        Implements IUnitOfWork.GetObjectByKey
        Return CType(Me.GetObjectByKey(key), T)
    End Function

    Public Sub Reroute_SaveChanges() _
        Implements IUnitOfWork.SaveChanges
        Me.SaveChanges()
    End Sub
    Public Shared Function GetBackendConfiguration() _
        As BackendConfiguration
        Dim backend As BackendConfiguration =
            New BackendConfiguration()
        backend.Backend = "MsSql"
        backend.ProviderName = "System.Data.SqlClient"

        CustomizeBackendConfiguration(backend)

        Return backend
    End Function

    ''' <summary>
    ''' Allows you to customize the BackendConfiguration of FluentModel.
    ''' </summary>
    ''' <param name="config">The BackendConfiguration of FluentModel.</param>
    Partial Private Shared Sub CustomizeBackendConfiguration _
        (ByRef config As BackendConfiguration)
    End Sub

End Class
Public Interface IFluentModelUnitOfWork
    Inherits IUnitOfWork
    ReadOnly Property RentalRates() As IQueryable(Of RentalRate)
    ReadOnly Property RentalOrders() As IQueryable(Of RentalOrder)
    ReadOnly Property Employees() As IQueryable(Of Employee)
    ReadOnly Property Customers() As IQueryable(Of Customer)
    ReadOnly Property Categories() As IQueryable(Of Category)
    ReadOnly Property Cars() As IQueryable(Of Car)
End Interface