Open Hunter21007 opened 7 years ago
thanks @Hunter21007, i will release a fix asap.
I have a class structure VERY similar to the original poster, and I'm having a problem with querying through derived classes. If query operations performed on a base-class IQueryable then the type is lost.
This produces the expected results (prints out some usernames from the database):
abstract class Query
{
public abstract IQueryable<BaseDocument> CreateQuery(ArangoDatabase database);
}
class UserQ : Query
{
public override IQueryable<BaseDocument> CreateQuery(ArangoDatabase database)
{
var query = database.Query<User>();
return query.Where(u => AQL.Length(u.Name) == 4);
}
}
class Program
{
static void RunQueryDisplayResults(ArangoDatabase database, Query query)
{
IQueryable<BaseDocument> results = query.CreateQuery(database);
foreach (BaseDocument obj in results)
Console.WriteLine(obj.ToString());
}
}
But if I try to perform any additional query operations in the top-level RunQueryDisplayResults() function (OrderBy(), Skip(), Take(), etc) then I get a bunch of BaseDocument objects (not User or whatever concrete type was passed into the function).
class Program
{
static void RunQueryDisplayResults(ArangoDatabase database, Query query)
{
IQueryable<Base> results = query.Run(database).Skip(1).Take(2);
foreach (Base obj in results)
Console.WriteLine(obj.ToString());
}
}
Produces the output below instead of printing 2 usernames:
ArangoConsoleTest.BaseDocument
ArangoConsoleTest.BaseDocument
I can do the OrderBy/Skip/Take/etc in the type-specific Query::CreateQuery and it will work. I can also cast the IQueryable<BaseDocument>
a concrete type (like IQueryable<User>
) in RunQueryDisplayResults() before doing Skip/Take and it will work. But both of these solutions aren't really doable when there are many document/query classes and defeat the use of inheritance in the first place.
@tonys1110 sorry for the delay, i did not get what exactly you trying to say
1- BaseDocument
.ToString() will print the class name, how query.Where(u => AQL.Length(u.Name) == 4)
returns username? am i missing something in your code?
2- please end you query with a Select
clause(always), and try again
3- can you provide a failing test, so i can test what you need to produce
Hi,
i have a usecase where i define a class:
and derivate:
if i use the Insert Method then the Id Property does not get filled by the client If i declare the id property in the derivate it works.
as i have found out you are using the GetAttribute by setting inherit to false this prevent the client from discovering the DocumentAttribute in the Base Class
typeSetting.TryAdd(m.Name, ReflectionUtils.GetAttribute<DocumentPropertyAttribute>(m, false));
My question is whether it is definitely required behavior or is it possible to change it in order to support inherited Identifier properties?
Thanks in advance
from public class DocumentPropertySetting : IDocumentPropertySetting: