예제 #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Query{TResultType}"/> class.
 /// </summary>
 /// <param name="connector">The database connector.</param>
 /// <param name="descriptor">The table type descriptor.</param>
 public Query(IDatabaseConnector connector, ITableTypeDescriptor descriptor)
 {
     this.Connector            = connector;
     this.Descriptor           = descriptor;
     this.SelectCommandBuilder = connector.GetCommandBuilderFactory().CreateSelectCommandBuilder(descriptor);
     this.Mapper = new DatabaseReaderMapper <TResultType>(connector, descriptor);
 }
예제 #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="NavigationKeyDescriptor"/> class.
        /// </summary>
        /// <param name="fromTypeDescriptor">From type descriptor.</param>
        /// <param name="toTypeDescriptor">To type descriptor.</param>
        /// <param name="fromProperty">From property.</param>
        /// <param name="toProperty">To property.</param>
        internal NavigationKeyDescriptor(ITableTypeDescriptor fromTypeDescriptor, ITableTypeDescriptor toTypeDescriptor, string fromProperty, string toProperty)
        {
            this.FromTypeDescriptor = fromTypeDescriptor;
            this.ToTypeDescriptor   = toTypeDescriptor;

            this.FromPropertyDescriptor = this.FromTypeDescriptor.AllProperties.First(x => x.PropertyName == fromProperty);
            this.ToPropertyDescriptor   = this.ToTypeDescriptor.AllProperties.First(x => x.PropertyName == toProperty);
        }
예제 #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="NavigationPropertyDescriptor"/> class.
 /// </summary>
 /// <param name="fromDescriptor">From descriptor.</param>
 /// <param name="property">The property information.</param>
 private NavigationPropertyDescriptor(ITableTypeDescriptor fromDescriptor, PropertyDecoration property)
 {
     this.PropertyDecoration = property;
     this.FromDescriptor     = fromDescriptor;
     this.PropertyInfo       = property.PropertyInfo;
 }
예제 #4
0
 /// <summary>
 /// Creates a list of <see cref="NavigationPropertyDescriptor"/> from a collection of <see cref="PropertyDecoration"/> and a <see cref="TableTypeDescriptor"/>.
 /// </summary>
 /// <remarks>
 /// This method will trim all null appearances if any.
 /// <see cref="Create(ITableTypeDescriptor, Descriptors.PropertyDecoration)"/>
 /// </remarks>
 /// <param name="fromDescriptor">The table type descriptor of the source property.</param>
 /// <param name="properties">Collection of property info.</param>
 /// <returns>A list of <see cref="ColumnPropertyDescriptor"/></returns>
 internal static List <INavigationPropertyDescriptor> Create(ITableTypeDescriptor fromDescriptor, IEnumerable <PropertyDecoration> properties)
 {
     return(properties.Select(x => Create(fromDescriptor, x)).Where(x => x != null).ToList());
 }
예제 #5
0
        /// <summary>
        /// Creates a new instance of <see cref="NavigationPropertyDescriptor"/> from a <see cref="PropertyDecoration"/> instance and a <see cref="TableTypeDescriptor"/>.
        /// </summary>
        /// <remarks>
        /// If the property is not decorated with the <see cref="NavigationAttribute"/> the method will return <c>null</c>.
        /// </remarks>
        /// <param name="fromDescriptor">The table type descriptor of the source property.</param>
        /// <param name="property">The property info to use.</param>
        /// <returns>A column property descriptor or null otherwise.</returns>
        internal static INavigationPropertyDescriptor Create(ITableTypeDescriptor fromDescriptor, PropertyDecoration property)
        {
            var descriptor = new NavigationPropertyDescriptor(fromDescriptor, property);

            return(descriptor.Initialize() ? descriptor : null);
        }
예제 #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DatabaseAccess"/> class.
 /// </summary>
 /// <param name="connector">A reference to the scoped database connector.</param>
 /// <param name="descriptor">The table type descriptor.</param>
 public DatabaseAccess(IDatabaseConnector connector, ITableTypeDescriptor descriptor) : this(null, connector, descriptor)
 {
 }
예제 #7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DatabaseAccess"/> class.
        /// </summary>
        /// <param name="serviceProvider">The service provider.</param>
        /// <param name="connector">The database connector.</param>
        /// <param name="descriptor">The table type descriptor.</param>
        public DatabaseAccess(IServiceProvider serviceProvider, IDatabaseConnector connector, ITableTypeDescriptor descriptor)
        {
            this.ServiceProvider = serviceProvider;

            // Sets the database connector.
            this.Connector = connector;

            // Sets the command batch manager.
            this.BatchManager = new BatchManager(connector);

            // Sets the Table Type Descriptor with reflected info about the table behind the entity.
            this.Descriptor = descriptor;

            // List of related data access entities.
            this.NavigationDatabaseAccesses = new List <INavigationDatabaseAccess>();

            this.Initialize();
        }
예제 #8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CommandBuilderManager"/> class.
        /// </summary>
        /// <param name="serviceProvider">A reference to the currently scoped service provider.</param>
        /// <param name="connector">A reference to the current database connection.</param>
        /// <param name="descriptor">A table type descriptor.</param>
        /// <exception cref="System.Exception">Couldn't create a Command Builder Factory.</exception>
        public CommandBuilderManager(IServiceProvider serviceProvider, IDatabaseConnector connector, ITableTypeDescriptor descriptor)
        {
            this.Factory = serviceProvider.GetServiceIfAvailable(connector.GetCommandBuilderFactory) ?? throw new Exception("Couldn't create a Command Builder Factory.");

            this._selectOneCommandBuilder    = new Lazy <ISelectOneCommandBuilder>(() => this.Factory.CreateSelectOneCommandBuilder(descriptor), true);
            this._selectCommandBuilder       = new Lazy <ISelectCommandBuilder>(() => this.Factory.CreateSelectCommandBuilder(descriptor), true);
            this._insertCommandBuilder       = new Lazy <IInsertCommandBuilder>(() => this.Factory.CreateInsertCommandBuilder(descriptor), true);
            this._updateCommandBuilder       = new Lazy <IUpdateCommandBuilder>(() => this.Factory.CreateUpdateCommandBuilder(descriptor), true);
            this._deleteCommandBuilder       = new Lazy <IDeleteCommandBuilder>(() => this.Factory.CreateDeleteCommandBuilder(descriptor), true);
            this._lastInsertIdCommandBuilder = new Lazy <ILastInsertIdCommandBuilder>(() => this.Factory.CreateLastInsertIdCommandBuilder(), true);
        }
예제 #9
0
 public ColumnPropertyDescriptorTest()
 {
     // We instantiate a TableTypeDescriptor object because ColumnPropertyDescriptor
     // is declared as internal, therefore we test it through TableTypeDescriptor
     ClientTableTypeDescription = DescriptorCache.Instance.GetTableTypeDescriptor(typeof(Client));
 }
 public TableTypeDescriptorTest()
 {
     // We set up this as a class property because we use it in almost every test (excepting one)
     ClientTableTypeDescription = DescriptorCache.Instance.GetTableTypeDescriptor(typeof(Client));
 }