tumtumtum / shaolinq Goto Github PK
View Code? Open in Web Editor NEWORM for .NET with full LINQ support for Postgres, Sqlite, MySql and SqlServer
License: Other
ORM for .NET with full LINQ support for Postgres, Sqlite, MySql and SqlServer
License: Other
Using Include to include a property always results in a related object, even if the related object should be null.
Calling Inflate() on an object reference which doesn't actually exist in the database throws a InvalidOperationException: Sequence contains no elements.
Should probably throw an exception that more explicitly defines the problem.
Steps to reproduce:
Shaolinq.AsyncRewriter 1.1.1.989
public partial class Class1
{
[RewriteAsync]
public int Foo() => 10;
}
This will produce an invalid C# code in GeneratedAsync.cs
file:
namespace ClassLibrary3
{
#pragma warning disable
using System;
using System.Threading;
using System.Threading.Tasks;
using global::ClassLibrary3;
public partial class Class1
{
public Task<int> FooAsync()
{
return FooAsync(CancellationToken.None);
}
=> 10;
public async Task<int> FooAsync(CancellationToken cancellationToken) => 10;
}
}
Hi,
I'm evaluating Shaolinq hoping to replace our npgsql-only implementation, to get real ORM and support for Linq, and so far I really like it!
I do have an issue when I insert new item with a timestamp (without timezone) column, the time ending up in the db is UTC (currently one hour off for me in Sweden). In the docs for npgsql (http://www.npgsql.org/doc/datetime.html) you can see that they don't touch the DateTime when the column is timestamp, but Shaolinq seems to always change it to UTC (see UniversalTimeNormalisingDateTimeSqlDateType.cs).
Is that really a correct behavior?
Thanks!
/Roger
How should ForUpdate work (with Postgres specifically)?
This works as expected:
dataModel.Categories.Where(x => x.Id == categoryId).ForUpdate().ToList().First();
SELECT "T0"."CategoryId", "T0"."Name"
FROM "Category" AS "T0"
WHERE (("T0"."CategoryId") = ('28ac0432-a4ca-409b-9c9c-510e7d917d93')) FOR UPDATE
These don't:
dataModel.Categories.ForUpdate().Where(x => x.Id == categoryId).ToList().First();
SELECT "T0"."CategoryId", "T0"."Name"
FROM "Category" AS "T0"
WHERE (("T0"."CategoryId") = ('28ac0432-a4ca-409b-9c9c-510e7d917d93'))
dataModel.Categories.Where(x => x.Id == categoryId).ForUpdate().First();
or
dataModel.Categories.ForUpdate().First(x => x.Id == categoryId);
SELECT "T0"."CategoryId", "T0"."Name"
FROM "Category" AS "T0"
WHERE (("T0"."CategoryId") = ('28ac0432-a4ca-409b-9c9c-510e7d917d93')) LIMIT 1
How to set a cascade on migration???
This query:
var salesTotals =
_postgresDataAccessModel.ItemSales.Where(
sales => sales.CompanyId == companyId && sales.LocationId == locationId &&
sales.ItemType == "Tap" &&
sales.DateSold >= adjustedStartTime && sales.DateSold <= endDate)
.GroupBy(sales => new {sales.MenuItemProductId, sales.DisplaySize})
.Select(sales => new
{
sales.Key.MenuItemProductId,
sales.Key.DisplaySize,
quantity = sales.Count()
}).ToList();
(over about 5000 records)
Takes two minutes to run in Shaolinq, and about 5 seconds in PGAdmin
I added Shaolinq postgres to my project. (its .net 4.5.2).,
I have the PostgresConfiguration and DataAccessModel classes but for some reason no DataAccessScope or TransactionScope classes. :/
I installed Shaolinq and Shaolinq.Sqlite through NPM. The last version "1.1.1.989" installs System.Data.Sqlite 1.0.103.0.
When this insruction :
var model = DataAccessModel.BuildDataAccessModel(configuration);
is about to be executed the debugger says that "System.Data.Sqlite 1.0.102.0" could not be found.
I forced the uninstall of version "1.0.103.0" and installed MSIL version 1.0.102 witch is deprecated. Now it gives me an ArgumentNullException on the same instruction.
Any suggestions would be greatly appreciated.
I'm decorating a property with the PrimaryKey attribute but I still get an error saying a Primary key is missing (it is still looking for Table Name + Id)
You're documentation shows a SelectForUpdate to do bulk updates, but it does not appear to be available
First of all, I just discovered your ORM an hour back, and want to thank you for creating something that worked with postgresql out of the box. Right now I can't even get Npgsql.EntityFramework to do that (ticket open on their site).
Now for the actual problem:
This may be a specific implementation issue, but I'm trying to work with custom schema name where all the new tables should reside and I keep getting exception that the schema doesn't exist (which is perfectly fine since it just created fresh database).
Having a browser through relevant source, I've concluded that we basically need to override this in PostgresSharedSqlDatabaseSchemaManager and create the schema explicitly and then proceed with base CreateSchema which assumes that the relevant schema name is already there.
I'll keep digging on how to fix this for a bit (pointers welcome!).
Hey, im new on .net dev
but i write some app, sites... in php using laravel. and this have a nice orm like this.
a nice function of eloquent is "timestamps"
Timestamps
By default, Eloquent expects created_at and updated_at columns to exist on your tables.
every new item is added a created_at time, and update populate column updated_at.
is possible to implement.
another function is SoftDelete.
nice working
tnk's
[]'s
AsyncRewriter inserts async method calls inside code that is within a lock section, however this won't compile (Cannot await in the body of a lock statement
):
lock (lockObj)
{
// can't do this inside a lock
await this.MethodAsync(cancellationToken).ConfigureAwait(false);
}
Can be worked around by using something like SemaphoreSlim
instead:
await semaphoreSlim.WaitAsync();
try
{
// synchronised code here
}
finally
{
semaphoreSlim.Release();
}
Hello,
It seems that CASCADE foreign key action is not supported at all. Is this by design or is this a bug?
There's a method FixAction(SqlColumnReferenceAction action) in the
D:\Dev\Shaolinq\src\Shaolinq\Persistence\Linq\SqlDataDefinitionExpressionBuilder.cs file that checks if the current Sql dialect supports Restrict when one tries to apply Cascade:
case SqlColumnReferenceAction.Cascade:
return this.sqlDialect.SupportsCapability(SqlCapability.RestrictAction) ? SqlColumnReferenceAction.Restrict : SqlColumnReferenceAction.NoAction;
Restrict is not enabled for Postgres. Postgres does support cascade actions for foreign key constraints.
Entity Framework syntax: http://msdn.microsoft.com/en-us/data/jj574232.aspx
NHibernate example: http://mikehadlow.blogspot.co.uk/2010/08/nhibernate-linq-eager-fetching.html
When I have a DataAcsessObject
with enum
property, and property has no values defined:
[DataAccessObject]
public abstract class DbType : DataAccessObject<Guid>
{
[PersistedMember]
public abstract Enum? EnumMember { get; set; }
}
public enum Enum
{
// No values defined here!
}
Shaolinq is trying to guess the size of the column and fails with the following exception:
XXX : System.Reflection.TargetInvocationException : Exception has been thrown by the target of an invocation.
----> System.InvalidOperationException : Sequence contains no elements
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, StackCrawlMark& stackMark)
at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
at System.Activator.CreateInstance(Type type, Object[] args)
at Shaolinq.Persistence.DefaultSqlDataTypeProvider.GetEnumDataType(Type type)
at Shaolinq.Persistence.DefaultSqlDataTypeProvider.GetSqlDataType(Type type)
at Shaolinq.Persistence.Linq.SqlDataDefinitionExpressionBuilder.BuildColumnDefinition(ColumnInfo columnInfo)
at Shaolinq.Persistence.Linq.SqlDataDefinitionExpressionBuilder.BuildCreateTableExpression(TypeDescriptor typeDescriptor)
at Shaolinq.Persistence.Linq.SqlDataDefinitionExpressionBuilder.Build()
at Shaolinq.Persistence.SqlDatabaseSchemaManager.BuildDataDefinitonExpressions(DatabaseCreationOptions options)
at Shaolinq.Persistence.SqlDatabaseSchemaManager.CreateDatabaseAndSchema(DatabaseCreationOptions options)
at Shaolinq.DataAccessModel.Create(DatabaseCreationOptions options)
at Namespace.Class.MethodName() in path/to/class.cs:line 34
--InvalidOperationException
at System.Linq.Enumerable.Max(IEnumerable`1 source)
at Shaolinq.Persistence.DefaultStringEnumSqlDataType`1.GetRecommendedLength(Type enumType)
at Shaolinq.Persistence.DefaultStringEnumSqlDataType`1.CreateConstraintDefaults(ConstraintDefaultsConfiguration defaultsConfiguration, Type type)
at Shaolinq.Persistence.DefaultStringEnumSqlDataType`1..ctor(ConstraintDefaultsConfiguration constraintDefaultsConfiguration)
That would be nice to have a more descriptive error message here, or use a fallback value for RecommendedLength
.
i dont see how to configure mysql with another port
Despite numerous Google searches, I can't seem to find any documentation.
So I have downloaded and installed Shaolinq, and am ready to get started writing code. But I have no idea what to write in order to create classes that ShaoLinq will understand, how to get ShaoLinq to create a database to match those classes, how to create, update, delete and retrieve objects, or anything.
Surely there must be some instructions somewhere, but I can't find them!
By default, Shaolinq generates an index with a NOT NULL
condition on each of the columns included in the index, e.g.:
CREATE UNIQUE NONCLUSTERED INDEX [Person_IsAdult_Name] ON [dbo].[Person] ([Name], [IsAdult]) WHERE ([Name] IS NOT NULL AND [IsAdult] IS NOT NULL)
But sometimes we might don't want the IS NOT NULL
conditions at all, e.g.:
CREATE UNIQUE NONCLUSTERED INDEX [Person_IsAdult_Name] ON [dbo].[Person] ([Name], [IsAdult])
In other cases, we might want to be able to specify some specific NOT NULL
conditions, e.g.:
CREATE UNIQUE NONCLUSTERED INDEX [Person_IsAdult_Name] ON [dbo].[Person] ([Name], [IsAdult]) WHERE ([Name] IS NOT NULL)
And in other cases, we need to be able to specify a totally different condition, e.g.:
CREATE UNIQUE NONCLUSTERED INDEX [Person_IsAdult_Name] ON [dbo].[Person] ([Name], [IsAdult]) WHERE ([Name] IS NOT NULL AND [IsAdult] = 1)
Would it be possible to implement this type of flexibility via the [Index]
attribute in Shaolinq?
At the moment an object is submitted to the cache only after it has been member initalised. Performance can be improved by submitting an object to the cache in case any of its members or members members reference itself because the partially constructed reference should be used.
Haven't had any success in figuring this out yet, so thought I'll open an issue. If i manage to figure it out, i'll send a pull for it.
I can see that it's likely happening from Sql92QueryFormatter but even when i give it space in formatter, it still doesn't get picked up. Will try to investigate more tomorrow.
Mono Sqlite provider stores Infinity as float.MaxValue but this means that float.MaxValue values are converted back into infinity.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.