Git Product home page Git Product logo

neyro.data's Introduction

Neyro.Data

Small and fast micro ORM.

Full description you can see in http://habrahabr.ru/post/218225/

Usage: Create data manager for MS Sql:

class MSSqlDataManager : DataManager 
{
    public MSSqlDataManager() : base(new SqlConnection("ConnectionString here")) { }
}

Model:

public class Product
{
        public int Id { get; set; }
        public string Name { get; set; }
        public string Description { get; set; }
        public int? Price { get; set; }
}

You can get data for model from SP: SP Code:

...
SELECT p.Id, p.Name, p.[Description], p.Price
    FROM dbo.Product p

C# Code:

using (var dm = new MSSqlDataManager())
{
    List<Product> res = dm.Procedure("Test").GetList<Product>();
}

Next example: You have SP:

SELECT 
        p.Id
        , p.Name, 
        , p.[Description]
        , p.Price
        , StorageId = s.Id
        , StorageName = s.Name
    FROM dbo.Product p 
    INNER JOIN dbo.Storages s ON s.Id = p.StorageId
    WHERE p.Id = @Id;
    
    SELECT 
        c.Id
        , c.Body
        , c.WriteDate
        , UserId = u.Id
        , UserName = u.Name
        , UserLocationId = l.Id
        , UserLocationName = l.Name
                          , c.ProductId
    FROM dbo.Comments c 
    INNER JOIN dbo.Users u ON u.Id = c.UserId
    INNER JOIN dbo.Locations l ON l.Id = u.LocationId 
    WHERE c.ProductId = @Id;

And you have models:

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

    public class UserModel
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public UserLocation Location { get; set; }

        public UserModel()
        {
            this.Location = new UserLocation();
        }
    }
    
    public class ProductComment
    {
        public int Id { get; set; }
        public string Body { get; set; }
        public DateTime WriteDate { get; set; }
        public UserModel User { get; set; }
        public int ProductId { get; set; }

        public ProductComment()
        {
            this.User = new UserModel();
        }
    }

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

    public class Product
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public string Description { get; set; }
        public int? Price { get; set; }
        public ProductStorage Storage { get; set; }
        public List<ProductComment> Comments { get; set; }

        public Product()
        {
            this.Storage = new ProductStorage();
            this.Comments = new List<ProductComment>();
        }
    }

You can get data:

Product res = dm.Procedure("Test").AddParams(new { id = 10 }).Get<Product, ProductComment>(p => p.Comments);

You can get master-detail data:

List<Product> res = dm.Procedure("Test")
      .GetList<Product, ProductComment>(
        (parents, detail)=>parents.First(p => p.Id == detail.ProductId).Comments
      );

You can use TVP params (for Ms Sql only):

dm.AddEnumerableParam("Details",
                    Enumerable.Range(1, 10)
                        .Select(e => new {id = e, name = string.Concat("Name", e.ToString())})
                    );

And a lot of other things.

Sorry for my English :)

neyro.data's People

Contributors

neyromant avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.