Skip to content
This repository has been archived by the owner on Nov 3, 2022. It is now read-only.
/ PromptSql Public archive

This library was developed to present your basic ado net operations with a simple fluent interface.

License

Notifications You must be signed in to change notification settings

brkmustu/PromptSql

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PromptSql

This library was developed to present your basic ado net operations with a simple fluent interface.

How to use?

1. Create a PromptSqlModule
public class SqlModule : PromptSqlModule
{
    public override string GetConnectionString()
    {
        return ConfigurationManager.AppSettings["DefaultConnection"];
    }
}
2. Command usage
        string sqlCommand = @"UPDATE [dbo].[Books] SET [Description] = 'Test Description' WHERE [Id] = 1";

        new SqlOperations<SqlModule>()
            .BeginOperation(x => x.CreateOptions(sqlCommand))
            .GetCommand()
            .ExecuteNonQuery();
3. Query usage

In order to make inquiries, you must first have a model where you will host the data and a sqlmapper.

get the model as below

public class Book
{
    public int Id { get; set; }
    public string ISBN { get; set; }
    public string Description { get; set; }
    public int? Age { get; set; }
    public DateTime? CreateDate { get; set; }

}

sqlmapper for this model should be as follows

public class BookMapper : SqlMapper<Book>
{
    protected override Book Map(DataRow source)
    {
        return new Book
        {
            Id = source.Field<int>("Id"),
            ISBN = source.Field<string>("ISBN"),
            Age = source.Field<int?>("Age"),
            CreateDate = source.Field<DateTime?>("CreateDate"),
            Description = source.Field<string>("Description")
        };
    }
}

now we are ready to query

        var data = new SqlOperations<SqlModule>()
            .BeginOperation(x => x.CreateOptions(query))
            .GetQuery<Book, BookMapper>()
            .FillData()
            .GetData();

that's all

About

This library was developed to present your basic ado net operations with a simple fluent interface.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages