pvginkel / nhibernate.odata Goto Github PK
View Code? Open in Web Editor NEWOData parser for NHibernate.
License: GNU Lesser General Public License v3.0
OData parser for NHibernate.
License: GNU Lesser General Public License v3.0
Hello,
I have a case where I need to filter data with a "not contains" clause. Someting like this:
$filter (substringof('outro',Nome) eq false)
But this clause throw a query not supported exception on NHibernate.OData.
Is there another way to do that? Or any plan to support this clause?
Thanks
Unit tests for member resolving must still be written.
Duration is currently only parsed. It cannot yet be used in queries. The problem with durations in OData is that it contains relative constructs that cannot be easily converted into a known .NET type because it contains numbers of months and years (which do not convert into absolute offsets).
It should be possible to specify column names case insensitive.
We have an ID column that is a bigint
in SQL and a long
in code. When we try to parse a query over the filter string it fails with an overflow exception if given values that are in the long
range but above the int
range.
For example
session.ODataQuery<OurEntityType>("$filter=Id eq 2147483647")
works fine, but
session.ODataQuery<OurEntityType>("$filter=Id eq 2147483648")
throws an overflow exception.
Thank you for the really nice library. If you have any questions about our setup, let me know :)
Hi,
Thanks for this great library. I'd love to see it grow.
I've got an issue with a queries such as:
people?$filter=EmploymentsList/any(o: o/Salary eq 2.5)
Where EmploymentsList is a property on People and is defined as:
private readonly ISet<Employment> employmentsList= new HashSet<Employment>();
public virtual IEnumerable<Employment> EmploymentsList
{
get { return this.employmentsList; }
}
I receive the following error:
"Cannot get collection item type"
Unfortunately, I cannot change the definition of .EmploymentsList and so would like to change nHibernate.odata instead. I can see the issue lies in NHibernate.OData.TypeUtil.TryGetCollectionItemType at this line:
System.Type enumerableType = collectionType.GetInterfaces().FirstOrDefault(x => x.IsGenericType && x.GetGenericTypeDefinition() == typeof(IEnumerable<>));
And enumerableType is returned as null.
Unfortunately, my knowledge of reflection isn't brilliant and would need some pointers but would adding a line such as:
if (enumerableType == null) enumerableType = collectionType;
be acceptable? If it is, I'll get on and write a unit test and send a pull request.
By looking at ODataExpression.cs one can notice that only 4 (out of 8) OData query options are supported currently:
case "$filter": ProcessFilter(value); break;
case "$orderby": ProcessOrderBy(value); break;
case "$top": ProcessTop(value); break;
case "$skip": ProcessSkip(value); break;
It would be nice to have support for $select, $expand, $inlinecount and $skiptoken.
In the CollectionMethods unit test class, there are tests such as:
RelatedParents/any(x:x/Int32 lt 5)
Where 'Int32' is a property of the class who's collection is being iterated over. However, in my code I need to iterate over a collection of basic types (strings, ints). When I attempt to do this, i.e.:
RelatedBasicTypeColl/any(x:x lt 5)
I get:
An exception of type 'NHibernate.QueryException' occurred in NHibernate.dll but was not handled in user code. Additional information: Could not find property t2.
Is this functionality that's expected to work?
A sample project should be added to the solution which implements a full OData service (maybe with some limitations).
Any plans to be compatible with .NET Standard?
indexof(Name, 'Value')
generates
CHARINDEX(Name, 'Value', 1)
instead if should generate
CHARINDEX('Value', Name, 1)
In the odata standard, you should be able to do something like this:
$filter=MyProperty eq null
However in NHibernate.OData it throws an exception:
Object reference not set to an instance of an object.
at System.Object.GetType()
at NHibernate.Criterion.Projections.Constant(Object obj)
at NHibernate.OData.CriterionVisitor.ComparisonExpression(ComparisonExpression expression)
at NHibernate.OData.ODataExpression.ProcessFilter(String value)
at NHibernate.OData.ODataExpression.ParseQueryString(String queryString)
at NHibernate.OData.ODataParser.ODataQuery(ISession session, Type persistentClass, String queryString)
Hi,
$inlinecount isn't currently supported and there is an opened issue about it (you plan to handle it in v2).
Can you add $count support before v2?
Any plans to support OData version 4?
Hi,
I'm trying to set the ODATA to perform case insensitive queries. But it is not working.
I did this:
var odataConfig = new ODataParserConfiguration {CaseSensitive = false};
var result = Sessao.ODataQuery(queryStringSelect, odataConfig).List();
I`m using a postgres database.
Am I missing something?
Thanks!
Hi,
I'm getting a "Query is not supported" exception when I try to make an odata query using substringof and 3 or more clauses. See this sample:
var result = session.ODataQuery("$filter=(DataNascimento eq datetime'1981-03-13T00:00:00' and substringof('Saurin',Nome) and substringof('21906522863',Cpf) and Id eq 55800)") .List();
The exception is:
Query is not supported
em NHibernate.OData.QueryVisitorBase`1.LogicalExpression(LogicalExpression expression)
em NHibernate.OData.CriterionVisitor.ComparisonExpression(ComparisonExpression expression)
em NHibernate.OData.CriterionVisitor.LogicalExpression(LogicalExpression expression)
em NHibernate.OData.CriterionVisitor.LogicalExpression(LogicalExpression expression)
em NHibernate.OData.ODataExpression.ProcessFilter(String value)
em NHibernate.OData.ODataExpression.ProcessQueryStringPart(String key, String value)
em NHibernate.OData.ODataExpression.ParseQueryString(String queryString)
em NHibernate.OData.ODataContext.ODataQuery(ISession session, Type persistentClass, String queryString, ODataParserConfiguration configuration)
em NHibernate.OData.ODataParser.ODataQuery[T](ISession session, String queryString)
em Ancode.Med.Testes.TesteOData.ConsultaComfiltro() na C:\TFSAncode\Ancode.Med\src\Ancode.Med\Ancode.Med.Testes\TesteOData.cs:linha 76
Thanks
I'm trying to create a WebAPI controller that can take and return DTOs and make it support OData.
The problem is that I'm separating the entities that are mapped to NHibernate and the DTOs. I need a way to apply OData queries based on DTOs (not on the NHibernate data models).
Looking at the code, it seems that if you can add the ability to call a user method (that will project the member name from one representation to another) inside Parser.ParseMember, it will do the job..
Thanks
MSFT documents the "substringof" function in the following documentation:
http://msdn.microsoft.com/en-us/library/hh169248(v=nav.71).aspx
The function looks like the following:
filter=substringof(‘Harry', Name)
This differs from NHibernate.OData in that the parameters are reversed. Here is nHIbernate.OData's implementation:
$filter=substringof(Name, 'Harry')
I was wondering if there is an official" way this method is supposed to be implemented documented somewhere?
The filter substringof('Child 10', Name) and Int32 eq 10
generates a QueryNotSupportException
, because it is parsed as ((SubStringOf(Child 10, Name) And Int32) Eq 10)
.
The OData protocol specifies that the eq
operator has higher precedence than and
operator. So the filter should be parsed as (SubStringOf(Child 10, Name) And (Int32 Eq 10))
.
Below is a test demonstrating this error:
[Test]
public void IncorrectOperatorPrecedence()
{
Verify(
"substringof('Child 10', Name) and Int32 eq 10",
Session.QueryOver<Child>().Where(x => x.Name == "Child 10" && x.Int32 == 10).List()
);
}
I'm having trouble running queries with $expand
or substringof
, the following error is generated
{
"odata.error": {
"code": "",
"message": {
"lang": "en-US",
"value": "An error has occurred."
},
"innererror": {
"message": "Exception has been thrown by the target of an invocation.",
"type": "System.Reflection.TargetInvocationException",
"stacktrace": " at System.Web.Http.ApiController.<InvokeActionWithExceptionFilters>d__1.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__0.MoveNext()",
"internalexception": {
"message": "Exception of type 'Antlr.Runtime.NoViableAltException' was thrown. [.Take[AeCAudit.Dominio.GrupoUsuario](.OrderBy[AeCAudit.Dominio.GrupoUsuario,System.Int32](.Where[AeCAudit.Dominio.GrupoUsuario](NHibernate.Linq.NhQueryable`1[AeCAudit.Dominio.GrupoUsuario], Quote(($it, ) => (Equal(Equal(Or(Equal(Convert($it.Nome), NULL), p1) ? NULLp3 : Convert(Convert($it.Nome).Contains(p2, )), p4), p5))), ), Quote(($it, ) => ($it.Id)), ), p6, )]",
"type": "NHibernate.Hql.Ast.ANTLR.QuerySyntaxException",
"stacktrace": " at NHibernate.Hql.Ast.ANTLR.ErrorCounter.ThrowQueryException()\r\n at NHibernate.Hql.Ast.ANTLR.HqlSqlTranslator.Translate()\r\n at NHibernate.Hql.Ast.ANTLR.QueryTranslatorImpl.DoCompile(IDictionary`2 replacements, Boolean shallow, String collectionRole)\r\n at NHibernate.Hql.Ast.ANTLR.ASTQueryTranslatorFactory.CreateQueryTranslators(IASTNode ast, String queryIdentifier, String collectionRole, Boolean shallow, IDictionary`2 filters, ISessionFactoryImplementor factory)\r\n at NHibernate.Hql.Ast.ANTLR.ASTQueryTranslatorFactory.CreateQueryTranslators(String queryIdentifier, IQueryExpression queryExpression, String collectionRole, Boolean shallow, IDictionary`2 filters, ISessionFactoryImplementor factory)\r\n at NHibernate.Engine.Query.QueryPlanCache.GetHQLQueryPlan(IQueryExpression queryExpression, Boolean shallow, IDictionary`2 enabledFilters)\r\n at NHibernate.Impl.AbstractSessionImpl.GetHQLQueryPlan(IQueryExpression queryExpression, Boolean shallow)\r\n at NHibernate.Impl.AbstractSessionImpl.CreateQuery(IQueryExpression queryExpression)\r\n at NHibernate.Linq.DefaultQueryProvider.PrepareQuery(Expression expression, IQuery& query, NhLinqExpression& nhQuery)\r\n at NHibernate.Linq.DefaultQueryProvider.Execute(Expression expression)\r\n at NHibernate.Linq.DefaultQueryProvider.Execute[TResult](Expression expression)\r\n at Remotion.Linq.QueryableBase`1.GetEnumerator()\r\n at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)\r\n at System.Web.Http.OData.Query.TruncatedCollection`1..ctor(IQueryable`1 source, Int32 pageSize)\r\n at System.Web.Http.OData.Query.ODataQueryOptions.LimitResults[T](IQueryable`1 queryable, Int32 limit, Boolean& resultsLimited)"
}
}
}
}
How can I use in conjunction with Asp.net and webapi so that the queries sent from the client (HTTP GET) are translated in server and send back to the client?
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.