Mongoid syntax for querying based on several sets of attributes - mongodb

Assuming I want to get 3 documents which fit one of these attributes
Class Question:
name=>a, topic=>b
name=>c, topic=>d
name=>e, topic=>f
What is the appropriate syntax for mongoid to get these?

According to mongoid query syntax:
Model.any_of({:name => a, :topic => b},
{:name => c, :topic => d},
{:name => e, :topic => f})

Related

Using Mapster to map from flat model to a model with nested properties in TypeAdapterConfig

Using EF Core 3 and Mapster I would like to map from a flat dto object to an object with a related sub-object.
i.e.
_ = TypeAdapterConfig<NoteVM, Note>.NewConfig()
.Map(d => d.Detail, s => s.Description)
.Map(d => d.Id, s => s.NoteId)
.Map(d => d.NoteTypeObject, s => s.NoteTypeString)
.IgnoreNullValues(true);
Where NoteTypeObject is an existing record on a table.
So in the mapping the NoteType object has to be retrieved from the db and attached to the Note record before the Note record is saved.
Can this be done in the config section or does this need to be done after the mapping but before the Note object is saved to the DB?
_ = TypeAdapterConfig<NoteVM, Note>.NewConfig()
.Map(d => d.Detail, s => s.Description)
.Map(d => d.Id, s => s.NoteId)
//get existing Id
.Map(d => d.NoteTypeObjectId, s => GetNoteTypeId(s.NoteTypeString))//lookup
.IgnoreNullValues(true);
If you are able to add a reference ID instead of object reference you can do something like the above.

Entity Framework : OrderBy while using Select extension method

I have a search predicate as follows
{x => (x.Actions.Any(y => (y.Id == 1))}
and sorting expression as below
{x => x.Actions.Select(y => y.Id)}
But every time I try to run this code below I get an exception on the execution of the query (I am using Sql linq provider)
context.Employees.Where(x => (x.Actions.Any(y => (y.Id == 1))).OrderBy(x => x.Actions.Select(y => y.Id)).First();
DbSortClause expressions must have a type that is order comparable.
Does this mean that the Select extension method can't be used with OrderBy method?

Composite key and where in in squeryl

How can I write deleteWhere clause in squeryl for entity with composite id?
val list: List[CompositeKey2[Long, Date]] = existing.map(x => x.id).toList
Schema.entities.deleteWhere(q => q.id in list)
Error:(82, 49) value in is not a member of org.squeryl.dsl.CompositeKey2[Long,java.util.Date]
Schema.entities.deleteWhere(q => q.id in list)
^
With a CompositeKey, the id method doesn't map directly to a column, so it isn't useful in an in clause. You'll have to structure your where to reference each column that makes up the private key individually. Without knowing the columns involved it's tough to be more specific, but something like
deleteWhere(q => existing.map(e => q.id1 === e.id1 and q.id2 === e.id2).reduce(_ or _))

Slick AST Library with ignore case operations

I have asked this question already in the slick google group. Posting it here if looking for help from ppl who do not check the group.
I am trying to implement a filter similar to scala-kendo . We had already developed this filter functionality using the plain queries. Now, I am trying to convert it to slick expressions, similar to what slick-kendo has done.
I need to implement case insensitive filtering. However, I am not able to find out how to do that. The members in scala.slick.ast.Library provides methods with case sensitive search only.
EDIT:
Adding the code:
private def predicate(e: E, f: Filter) = {
val (c, v) = (colNode(e, f.field), LiteralNode(f.value))
val L = Library
def \(fs: FunctionSymbol, nodes: Node*) = fs.typed[Boolean](nodes: _*)
Column.forNode[Boolean](f.operator match {
case "EqualTo" => \(L.==, c, v)
case "NotEqualTo" => \(L.Not, \(L.==, c, v))
case "GreaterThen" => \(L.>, c, v)
case "GreaterThenOrEqualTo" => \(L.>=, c, v)
case "LessThen" => \(L.<, c, v)
case "LessThenOrEqualTo" => \(L.<=, c, v)
case "StartsWith" => \(L.StartsWith, c, v)
case "StartsWithIgnore" => \(L.StartsWith, c, v)
case "EndsWith" => \(L.EndsWith, c, v)
case "Contains" => \(L.Like, c, LiteralNode(s"%${f.value}%"))
case "DoesNotContain" => \(L.Not, \(L.Like, c, LiteralNode(s"%${f.value}%")))
})
}
As you can see above, there are methods like StartsWith, EndsWith etc in Library, but I need something like StartsWithIgnoreCase, EndsWithIgnoreCase etc
Can someone provide any suggestions to implement this feature I need.
If I understand you correctly you want something like here: http://slick.typesafe.com/doc/3.0.0-RC3/queries.html#sorting-and-filtering - see the 4. example "val q4 = coffees.filter ...". This part of the docs is also valid for slick 2.x.
Finally, the solution is found. Pasting here for others benefit. Went through the slick codebase and found out how to covert node to column and apply lowercase on column.
case "EqualToIgnoreCase" => \(L.==, (Column.forNode[String](c).toLowerCase).toNode, LiteralNode(f.value.toLowerCase()))

Automapper, mapping to a complex object

I have 2 classes i'm trying to map namely
1) Entity
2) DTO
I'm trying to map Entity.Foo to DTO.Child.Foo
Obviously the below will not work, how do I achieve this. I need to create a new instance of Child and then attach that to the Mapper and then set the Foo property but my AutoMapper skills are not that good!
Mapper.CreateMap<Entity, DTO>()
.ForMember("Child.Foo", m => m.MapFrom(entity => entity.Foo))
Mapper.CreateMap<Entity, DTO>()
.ForMember(d => d.Foo,
o => o.ResolveUsing(s => new DTO.Child { Foo = s.Foo }))
// comment