Giter VIP home page Giter VIP logo

simplestack.orm's Introduction

simplestack

Owin port of simplestack (NServiceKit)

simplestack.orm's People

Contributors

andrealbertto avatar avtc avatar bgrainger avatar dependabot[bot] avatar galimage avatar kaporos avatar naydfakto avatar schulz3000 avatar vdaron avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

simplestack.orm's Issues

SQLite doest not support class containing a property named 'Order'

The following code

[Alias("tests")]
public class TestClass
{
    [Alias("id")]
    public int Id { get; set; }

    [Alias("order_test")]
    public int Order { get; set; }
}

[Fact]
public void Test()
{
    OrmConnectionFactory connectionFactory =
        new OrmConnectionFactory(new SqliteDialectProvider(), "Mode=Memory;Cache=Shared;");
    using (var connection = connectionFactory.OpenConnection())
    {
        var tmp = connection.Select<TestClass>();
    }
}

return an error "Microsoft.Data.Sqlite.SqliteException : SQLite Error 1: 'near "Order": syntax error'."

Should Document 'Available Attributes' section

Hello,

Many people don't use this extension because the 'Alias' attribute is not documented anywhere. So they believe there is a limitation that properties must eventually match database column names.

I think it would be wise to include it in the available attributes section.

Thx for your work.

The "onlyField" parameter does not work in update query

Version: 1.2.0-beta98

On update queries, the "onlyField" parameter does not work using MySQL, we always get an exception:

MySqlException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE id=20' at line 1

Where in JoinSqlBuilder not supported

public class Bar
{
[PrimaryKey]
public int Id { get; set; }

        public string BarProperty { get; set; }
    }

    public class Foo
    {
        [PrimaryKey]
        public int Id { get; set; }

        public string FooProperty { get; set; }
    }

    public class BarView
    {
        public string BarProperty { get; set; }

        public string FooProperty { get; set; }
    }

    [Test]
    public void JoinSqlBuilderWithWhereCondition()
    {
        IDialectProvider dialectProvider = new SqliteDialectProvider();
        using (OrmConnection connection = dialectProvider.CreateConnection(":memory:"))
        {
            connection.Open();

            connection.CreateTable<Bar>(true);
            for (int i = 0; i < 10; i++)
            {
                connection.Insert(new Bar { Id = i, BarProperty = i + "_Bar" });
            }

            connection.CreateTable<Foo>(true);
            for (int i = 0; i < 10; i++)
            {
                connection.Insert(new Foo { Id = i, FooProperty = i + "_Foo" });
            }

            var builder = new JoinSqlBuilder<Bar, Bar>(dialectProvider)
                .Join<Bar, Foo>(x => x.Id, x => x.Id)
                .Select<Bar>(x => new {x.BarProperty})
                .Select<Foo>(x => new {x.FooProperty})
                .Where<Bar>(x => x.Id > 5);
            IList<BarView> views = connection.Query<BarView>(builder.ToSql()).ToList();
            Assert.AreEqual(4, views.Count);
            foreach (var view in views)
            {
                Assert.AreEqual(view.BarProperty.Replace("_Bar", string.Empty), view.FooProperty.Replace("_Foo", string.Empty));
            }

            connection.Close();
        }
    }

Create table on closed connection do not throw exception

    public class Bar
    {
        [PrimaryKey]
        public int Id { get; set; }
    }

    [Test]
    public void TestCreateTableConnectionClosed()
    {
        using (OrmConnection connection = new SqliteDialectProvider().CreateConnection(":memory:"))
        {
            Assert.Throws<Exception>(() => connection.CreateTable<Bar>(true));
            connection.Close();
        }
    }

simplestack.org not available

don't know if it's the correct place to notify

simplestack.org is not available. It leads to a 404 page at github

Alias not supported to map db columns to class properties

    public class Bar
    {
        [PrimaryKey]
        public int Id { get; set; }

        [Alias("Test")]
        public string Foo { get; set; }
    }

            [Test]
    public void TestPropertyWithAliasCorrectlyMappedInClass()
    {
        using (OrmConnection connection = new SqliteDialectProvider().CreateConnection(":memory:"))
        {
            connection.Open();
            connection.CreateTable<Bar>(true);
            connection.Insert(new Bar {Id = 1, Foo = "test"});
            Bar bar = connection.FirstOrDefault<Bar>(x => x.Id == 1);
            Assert.IsNotNull(bar);
            Assert.AreEqual(1, bar.Id);
            Assert.AreEqual("test", bar.Foo);
            connection.Close();
        }
    }

    [Test]
    public void TestGetObjectByPropertyWithAlias()
    {
        using (OrmConnection connection = new SqliteDialectProvider().CreateConnection(":memory:"))
        {
            connection.Open();
            connection.CreateTable<Bar>(true);
            connection.Insert(new Bar { Id = 1, Foo = "test" });
            Bar bar = connection.FirstOrDefault<Bar>(x => x.Foo == "test");
            Assert.IsNotNull(bar);
            Assert.AreEqual(1, bar.Id);
            Assert.AreEqual("test", bar.Foo);
            connection.Close();
        }
    }

CountAsync does not works when argument is a predicate, In MySQL Version

Hello,

Thanks for building this wonderful project. I was using an older version of simplestack.orm, and recently migrated to the latest beta version. I have noted that CountAsync(expression) does not works, for example following query results in exception.

long unclosedChecks = await conn.CountAsync<OrderCheck>(s => s.OrderId == order.Id && s.CompletedAt == null);

After some debugging, i changed the

public async Task<long> CountAsync<T>(Expression<Func<T, bool>> expression)
{
	return await CountAsync<T>( e => { e.Select(expression); } );
}

To

public async Task<long> CountAsync<T>(Expression<Func<T, bool>> expression)
{
	return await CountAsync<T>( e => { e.Where(expression); } );
}

In OrmConnectionAsyn.cs it worked.

e.Select(expression); was intentional ?

Non-generic CRUD support

Hi, I have several issue with some CRUD operation ex) CreateTableAsync.

My codes need to deal with dynamic type of T, but the generic type requires explicit type definition.

They use typeof(T) instead internally, but modifier limits to reuse these methods.

It'll be nice to add public non-generic CRUD methods.

Thanks for your support.

SelectAll in JoinSqlBuilder do not take alias into account

    public class Bar
    {
        [PrimaryKey]
        public int Id { get; set; }

        [Alias("Test")]
        public string BarProperty { get; set; }
    }

    public class Foo
    {
        [PrimaryKey]
        public int Id { get; set; }

        public string FooProperty { get; set; }
    }

    [Test]
    public void Test()
    {
        IDialectProvider dialectProvider = new SqliteDialectProvider();
        using (OrmConnection connection = dialectProvider.CreateConnection(":memory:"))
        {
            connection.Open();

            connection.CreateTable<Bar>(true);
            connection.CreateTable<Foo>(true);

            var builder = new JoinSqlBuilder<Bar, Bar>(dialectProvider)
                .Join<Bar, Foo>(x => x.Id, x => x.Id)
                .SelectAll<Bar>()
                .Select<Foo>(x => new {x.FooProperty});
            IList<BarView> views = connection.Query<BarView>(builder.ToSql(), builder.Parameters).ToList();
            connection.Close();
        }
    }

=> generate this query :

SELECT "Bar"."Id","Bar"."Test","Foo"."FooProperty" AS "FooProperty"
FROM "Bar"
INNER JOIN "Foo" ON "Bar"."Id" = "Foo"."Id"

instead of :

SELECT "Bar"."Id","Bar"."Test" AS "BarProperty","Foo"."FooProperty" AS "FooProperty"
FROM "Bar"
INNER JOIN "Foo" ON "Bar"."Id" = "Foo"."Id"

Failed to set binary column to null using Update on MSSQL

Updating a model containing null in bytes[] property causes an error:
"Implicit conversion from data type nvarchar to varbinary is not allowed. Use the CONVERT function to run this query."

This is the cause of passing parameters as Dictionary<string, object> to Dapper.
Dapper converts the dictionary to DynamicParameters without knowing the DbType of the passed null value.
SqlDbCommand adds the new parameter with DbType.String (by default) and null convered to DbNull.Value.
For binary and varbinary columns DBNull.Value does not work without setting the DbType, while other column types works fine.

Reference code in Dapper: https://github.com/DapperLib/Dapper/blob/a31dfd3dd4d7f3f2580bd33c877199d7ef3e3ef9/Dapper/DynamicParameters.cs#L271

Select TOP

just want to request new feature in SqlServerDialectProvider, i want to create Sql query with Select TOP in sql server, could you provide interface for this, or could you create property my be _top for compose in select statment?

Insert is void?

Hello,

I think I have found a severe limitation on Insert. The method is void and does not return the ID of the newly inserted record.

Is it possible, not documented maybe, to get the new primary key from the Insert or InsertAsync?

Thanks.

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.