コード例 #1
0
        /// <summary>
        /// Loads the specified XML document and optionally validates it. Then the document is deserialized using the specified <see cref="IDbSchemaConfiguration"/> object.
        /// </summary>
        /// <param name="dbXmlDocument"><see cref="XDocument"/> object containing the database schema to load.</param>
        /// <param name="validateSchema">Indicates whether or not to validate the dbXmlDocument parameter before attempting to deserialize it.</param>
        /// <param name="config"><see cref="IDbSchemaConfiguration"/> object to use for deserialization.</param>
        public void LoadDbXmlDocument(XDocument dbXmlDocument, bool validateSchema, IDbSchemaConfiguration config)
        {
            if (dbXmlDocument == null)
            {
                throw new ArgumentNullException(nameof(dbXmlDocument));
            }
            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }

            // Now optionally validate against our database XML schemas
            if (validateSchema)
            {
                var builder = new StringBuilder();
                ValidateDbXmlDocument(dbXmlDocument, (sender, args) =>
                {
                    builder.AppendLine(args.Message);
                }, false);

                // Check for validation errors before proceeding to deserialize the database schema document
                if (builder.Length > 0)
                {
                    throw new XmlSchemaValidationException(builder.ToString());
                }
            }

            _dbConfig = config;
            _dbConfig.Deserialize(dbXmlDocument);
        }
コード例 #2
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="database">A Shared Database connection.</param>
 /// <param name="schemaConfig">Configures which DB Schema to find all the tables in.</param>
 public DapperDataAccess(ISharedDatabase database, IDbSchemaConfiguration schemaConfig)
 {
     _schemaConfig = schemaConfig;
     _database     = database;
 }