예제 #1
0
        /// <summary>
        /// Writes CRUD interface methods definition for the specified table.
        /// </summary>
        /// <param name="table">The table to write interface for.</param>
        public void WriteTableDataProviderInterface(TableInfo table)
        {
            MethodSignature[] signatures = new MethodSignature[4];
            signatures[0] = MethodSignature.GetCreateSignature(table);
            signatures[1] = MethodSignature.GetUpdateSignature(table);
            signatures[2] = MethodSignature.GetDeleteSignature(table);
            signatures[3] = MethodSignature.GetReadSignature(table);

            foreach (var signature in signatures)
            {
                WriteLine(signature.ToString("i", null));
            }
        }
예제 #2
0
        /// <summary>
        /// Writes data provider methods definition for the specified table.
        /// </summary>
        /// <param name="table">The table to write methods for.</param>
        public void WriteTableDataProviderImplementation(TableInfo table)
        {
            MethodSignature signature = MethodSignature.GetCreateSignature(table);
            IMethodBuilder  builder   = new CreateMethodBuilder(table);

            WrapMethodBody(signature, builder);

            signature = MethodSignature.GetUpdateSignature(table);
            builder   = new UpdateMethodBuilder(table);
            WrapMethodBody(signature, builder);

            signature = MethodSignature.GetDeleteSignature(table);
            builder   = new DeleteMethodBuilder(table);
            WrapMethodBody(signature, builder);

            signature = MethodSignature.GetReadSignature(table);
            builder   = new ReadMethodBuilder(table);
            WrapMethodBody(signature, builder);
        }
예제 #3
0
        /// <summary>
        /// Gets the method body without definition and curly braces.
        /// </summary>
        public string GetMethodBody()
        {
            StringBuilder buffer    = new StringBuilder(512);
            var           signature = MethodSignature.GetReadSignature(_table);
            var           parameter = signature.Parameters.First();

            buffer.AppendLine("using (var connection = GetReadOnlyConnection())");
            buffer.AppendLine("{");
            buffer.AppendLine("connection.Open();");

            buffer.AppendFormat(
                "return connection.Query<{0}>(\"SELECT * FROM {1} WHERE {2} = @{3}\", new {{ {3} }})",
                _table.EntityName,
                _table.FullName,
                _table.IdentityColumn.FullName,
                parameter.Key);

            buffer.AppendLine(".SingleOrDefault();")
            .AppendLine("}");

            return(buffer.ToString());
        }