Skip to content

ThiagoBarradas/sqlclient-parsetoobject

Repository files navigation

Build Status Quality Gate Status NuGet Downloads NuGet Version

SqlClient.ParseToObject

Get a full object (with nested complex objects) from Microsoft.Data.SqlClient. Created with .NET Core support;

Install via NuGet

PM> Install-Package SqlClient.ParseToObject

How to use

Optional Packages (to run next code):

Install-Package Dapper 

Demo Models:

public class UserModel
{
	public string Id { get; set; }

	public string Name { get; set; }

	public int Weight { get; set; }

	public DateTime Birthdate{ get; set; }

	public AddressModel Address { get; set; }
}

public class AddressModel
{
	public string Line1 { get; set; }

	public string Line2 { get; set; }

	public string City { get; set; }
}

Code:


var query = @"SELECT 
				U.Cod AS Id,
				Name,
				Birthdate,
				Weight,
				A.Line1 as [Address.Line1],
				A.Line2 as [Address.Line2],
				A.City as [Address.City]
			  FROM User U INNER JOIN Address A ON U.AddressCod = A.Cod
			  WHERE Name = @Name";

var parameters = new 
{
	Name = "Thiago Barradas"
};

using (var sqlConnection = new SqlConnection(connectionString))
{
    var reader = sqlConnection.ExecuteReader(query, parameters);

    List<User> users = reader.GetResults<User>();
}

How can I contribute?

Please, refer to CONTRIBUTING

Found something strange or need a new feature?

Open a new Issue following our issue template ISSUE TEMPLATE

Changelog

See in nuget version history

Did you like it? Please, make a donate :)

if you liked this project, please make a contribution and help to keep this and other initiatives, send me some Satochis.

BTC Wallet: 1G535x1rYdMo9CNdTGK3eG6XJddBHdaqfX

1G535x1rYdMo9CNdTGK3eG6XJddBHdaqfX