LScape.Data 1.3.1

.NET Standard 2.0
dotnet add package LScape.Data --version 1.3.1
NuGet\Install-Package LScape.Data -Version 1.3.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="LScape.Data" Version="1.3.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add LScape.Data --version 1.3.1
#r "nuget: LScape.Data, 1.3.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install LScape.Data as a Cake Addin
#addin nuget:?package=LScape.Data&version=1.3.1

// Install LScape.Data as a Cake Tool
#tool nuget:?package=LScape.Data&version=1.3.1


LScape.Data is a Micro-ORM with the intention of providing a simple way to map between objects and database objects. It's intended to work with poco objects, which are either decorated with attributes, or configured through a a fluent api.

The project has expanded to include extensions to IDbConnection, IDbCommand, and IDbDataReader, to provide simpler ways of interacting with a database from your code.

The project has been re-written as a .netstandard 2.0 library and has no other dependancies.

Using the Mapping

At the core of LScape.Data is the Map class. You can create a map for any class just by creating a new Map object.

using LScape.Data.Mapping;


var map = new Map<MyClass>();
MyClass object = map.Create(dataReaderSingle);
IEnumerable<MyClass> objects = map.CreateEnumerable(dataReaderMultiple);

You can configure which properties of the Class take part in mapping by either decorating with the attributes CalculatedAttribute, IgnoredAttribute and KeyAttribute, or using the fluent functions Calculated, Ignore and Key on the Map class itself.

To change which column and table the class is associated with you can use the ColumnAttribute and TableAttribute, or directly change them in the Map with the properties.

public class MyClass
    public int Id { get; set; }
    public string Name { get; set; }

    public string Email { get; set; }

    public DateTime Created { get; set; }

    public DateTime? Deleted { get; set; }

    public byte[] ImageData { get; set; }

/// Properties can be specified by name, or linq
var map = new Map<MyClass>().Key(c => c.Id).Calculated("Created", "Deleted");
/// Manipulation

map.TableName = "MyTable";
map.Fields(f => f.PropertyName == "Name").ColumnName = "UserName";
map.Fields(f => f.PropertyName == "ImageData").FieldType = FieldType.Ignore;


The second part of LScape.Data is the Mapper class, it's basically a global holder for mapped types, and holds the default configuration for how the Map class behaves.

To get a Map from the Mapper:

var Map = Mapper.Map<T>();

A Map pulled from the mapper is cached and retains any configuration applied to it. The PreMap command takes types and calculated maps upfront to save on creation time later. You can also store any Map already created in the Mapper with SetMap command.

Clearing the Cached maps is through ClearMaps.

Mapper Configuration

You can change the default behaviour of the Map by altering the Configuration default held by the Mapper class, or creating a new configuration and passing it into the Constructor of Map.

The configurations are the convention to use for table and column names from the class and properties:

Input: SomeName

Exact:          SomeName
LowerCase:      somename
UpperCase:      SOMENAME
SplitCase:      Some_Name
SplitCaseLower: some_name
SplitCaseUpper: SOME_NAME

You can also supply delegates (Func<>) to handle the names if you need something else.

Mapper.Configuraton.TableNameConvert = (input) => $"tbl_{input}";

There are also Match functions for Ignore, Calculated and Key that take delegates that have the name and type, so you handle general cases without having to configure for every class.

Mapper.Configuration.KeyMatch = (name, type) => name == "Id" && type == typeof(int);

IDbConnection Extensions

There are convience extensions added to IDbCommand and IDataReader but the main ones are on IDbConnection.

Thery provide many ways to query the database, as well as lots of crud operations. They use the Mapper configured Maps to handle opjects.

There is an Async version of each method.

Here are a few examples

var connection = new SqlConnection(connectionString);


MyClass rst = connection.ExecuteQuery<MyClass>("SELECT * FROM MyTable WHERE Id = 1");

List<MyClass> rst2 = connection.ExecuteQueryMany<MyClass>("SELECT * FROM MyTable").ToList();

MyClass rst3 = await connection.ExecuteQueryAsync<MyClass>("SELECT * FROM MyTable WHERE Id = @Id", new {Id = 1});

MyClass rst4 = connection.Get<MyClass>(new {Id = 1});

/// String values with '%' automatically cause the query to change the comparison to a like
List<MyClass> rst5 = await connection.GetAllASync<MyClass>(new {Name = "%Test%"});

int total = connection.Count<T>();

/// Insert and updates return the object as read from the database after its been saved
var savedEntity = connection.Insert(myobject);

await connection.DeleteAsync(myobject);

connection.Delete<MyClass>(new {Name = "Geoff"});
Product Versions
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows net7.0 net7.0-android net7.0-ios net7.0-maccatalyst net7.0-macos net7.0-tvos net7.0-windows
.NET Core netcoreapp2.0 netcoreapp2.1 netcoreapp2.2 netcoreapp3.0 netcoreapp3.1
.NET Standard netstandard2.0 netstandard2.1
.NET Framework net461 net462 net463 net47 net471 net472 net48 net481
MonoAndroid monoandroid
MonoMac monomac
MonoTouch monotouch
Tizen tizen40 tizen60
Xamarin.iOS xamarinios
Xamarin.Mac xamarinmac
Xamarin.TVOS xamarintvos
Xamarin.WatchOS xamarinwatchos
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.3.1 1,320 11/13/2017
1.3.0 1,918 11/12/2017

Added new commands to IDbConnection, and small comment fixes.