fileMovementRepository.GetAll()
.Where(fm => repository.GetAll().Select(f => f.Id).Contains(fm.FileId) && fm.TransferredById == userId)
.Include(f => f.User).Include(f => f.File).ThenInclude(f => f.Category)
.OrderByDescending(f => f.MovedOn)
.GroupBy(f => f.FileId)
.Select(f=>f.First())
.ToList();
The following error is showing on runtime
An unhandled exception occurred while processing the request.
InvalidOperationException: The LINQ expression 'GroupByShaperExpression:
KeySelector: f.FileId,
ElementSelector:EntityShaperExpression:
EntityType: FileMovement
ValueBufferExpression:
ProjectionBindingExpression: EmptyProjectionMember
IsNullable: False
.First()' could not be translated. Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly by inserting a call to 'AsEnumerable', 'AsAsyncEnumerable', 'ToList', or 'ToListAsync'. See https://go.microsoft.com/fwlink/?linkid=2101038 for more information.
Microsoft.EntityFrameworkCore.Query.RelationalSqlTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
InvalidOperationException: The LINQ expression 'GroupByShaperExpression: KeySelector: f.FileId, ElementSelector:EntityShaperExpression: EntityType: FileMovement ValueBufferExpression: ProjectionBindingExpression: EmptyProjectionMember IsNullable: False .First()' could not be translated. Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly by inserting a call to 'AsEnumerable', 'AsAsyncEnumerable', 'ToList', or 'ToListAsync'. See https://go.microsoft.com/fwlink/?linkid=2101038 for more information.
Use ToList() before GroupBy and it will work as expected.
fileMovementRepository.GetAll()
.Where(fm => repository.GetAll().Select(f => f.Id).Contains(fm.FileId) && fm.TransferredById == userId)
.Include(f => f.User).Include(f => f.File).ThenInclude(f => f.Category)
.OrderByDescending(f => f.MovedOn)
.ToList()
.GroupBy(f => f.FileId)
.Select(f=>f.First())
.ToList();
Related
I want to create index with some condition,like with querycontainer to add conditional filters.
PropertiesDescriptor<object> ps = new PropertiesDescriptor<object>();
if (condition)
{
ps.Text(s => s.Name(name[1]));
}
if(condition)
{
ps.Number(s => s.Name(name[1]));
}
if (!_con.client.Indices.Exists(indexname).Exists)
{
var createIndexResponse = _con.client.Indices.Create(indexname, index => index.Settings(s => s.NumberOfShards(1).NumberOfReplicas(0))
.Map(m=>m.Properties(ps)));
}
But i receive following error, can you guide me how to acheive this.
cannot convert from 'Nest.PropertiesDescriptor<object>' to 'System.Func<Nest.PropertiesDescriptor<object>, Nest.IPromise<Nest.IProperties>>'
You are almost there, just change Properties part to m.Properties(p => ps).
_con.client.Indices.Create(indexname,
index => index.Settings(s => s.NumberOfShards(1).NumberOfReplicas(0)).Map(m=>m.Properties(p => ps)));
Hope that helps.
I am executing the following query in LINQPad:
Tickets.GroupJoin(UserRoles, t => t.AuthorId, r => r.UserId, (ticket, roles) => new {
AuthorId = ticket.AuthorId,
AuthorRoles = roles.Select(r => r.Role).Distinct(),
Message = ticket.Message,
Replies = ticket.TicketReplies.GroupJoin(UserRoles, reply => reply.AuthorId, role => role.UserId, (reply, roles2) => new {
AuthorId = reply.AuthorId,
AuthorRoles = roles2.Select(r => r.Role).Distinct(),
Message = reply.Message
})
}).Take(1000)
Where AuthorId is a string, AuthorRoles a list of ints, and Message a string. This query performs terribly. This query results in an excess of 2000 queries being sent from LINQPad.
Why is LINQPad unable to translate this into a single SQL query?
Can I formulate my query differently so that LINQPad is able to perform better?
I am trying to use the BulkAll() method to add documents to my index.
The index is created using a mapping which works using IndexMany():
client.CreateIndex(indexName, c => c
.Settings(s => s
.NumberOfShards(shardCount).NumberOfReplicas(replicaCount))
.Mappings(ms => ms
.Map<MyDocument>(m => m.AutoMap())
));
I then try to use BulkAll():
Console.WriteLine("Indexing documents into elasticsearch...");
var waitHandle = new CountdownEvent(1);
var bulkAll = client.BulkAll(docsToUpload, b => b
.Index(indexName)
.BackOffRetries(2)
.BackOffTime("30s")
.RefreshOnCompleted(true)
.MaxDegreeOfParallelism(4)
.Size(100)
);
bulkAll.Subscribe(new BulkAllObserver(
onNext: (b) => { Console.Write("."); },
onError: (e) => { throw e; },
onCompleted: () => waitHandle.Signal()
));
waitHandle.Wait();
Console.WriteLine("Done.");
This logs out a row of "....." followed by "Done" as expected, but my index is empty when I check it.
If I don't do the first step of creating the index then the bulk upload creates an index with default mappings, but I can't use it without my mappings.
I am in the process of upgrading NEST from 1.6.2 to 2.3.3. Getting type not found for FilterDescriptor, FilterContainer.
What are the equivalent types in NEST 2.3.3?
Thanks in advance.
UPDATE
Based on the response from #RussCam, here is what I got
in 1.6.2
public static Func<FilterDescriptor<Property>, FilterContainer> AddressComponents(string address)
{
return filter => filter
.Query(q => q
.MultiMatch(multimatch => multimatch
.OnFields(
f => f.Address,
f => f.Address.Suffix("shingles"))
.Query(address)
.Type(TextQueryType.CrossFields)
.Operator(Operator.And)
)
);
}
to 2.3.3
public static Func<QueryContainerDescriptor<Property>, QueryContainer> AddressComponents(string address)
{
return q => q
.MultiMatch(multimatch => multimatch
.Fields(f => f
.Field(p => p.Address)
.Field(p => p.Address.Suffix("shingles")))
.Query(address)
.Type(TextQueryType.CrossFields)
.Operator(Operator.And)
);
}
The equivalent types in NEST 2.3.3 are QueryContainerDescriptor<T> and QueryContainer; filters and queries merged in Elasticsearch 2.0 into one concept, queries, that can be used in either a query context or a filter context, so the change in NEST reflects this.
There's a blog post talking about the high level changes, as well as some documentation for 2.x clients.
I'm using Google's ruby api client to talk to big query and I have it all set up and working, except for queries where I'm getting this error:
{"error"=>
{"errors"=>
[{"reason"=>"required",
"domain"=>"global",
"message"=>"Required parameter is missing"}],
"code"=>400,
"message"=>"Required parameter is missing"}}
Here is what I'm calling:
bq = client.discovered_api("bigquery", "v2")
resp = client.execute(
bq.jobs.query,
{ "projectId" => "1234",
"query" => "SELECT count(*) FROM [api_logs.api_logs_week_28__Jul_2012] where timestamp >= 1341817200 and timestamp <= 1341903599"
}
)
The frustrating part is on the query api docs, these same exact parameters work just fine. Any ideas?
First- - I don't know ruby, but I do know bigquery, so I've taken a look at the ruby google drive example and tried to adapt it:
result = client.execute(
:api_method => bq.jobs.query,
:body_object => { "query" => "SELECT 17" },
:parameters => { "projectId => "1234" })
Essentially the projectId needs to be a parameter, and the query needs to be in the post data.