ExecuteJoinedDataSet but with Where() - subsonic

I did some searching and see that ExecuteJoinedDataSet will not work with the Where clause in 2.1. If I want to query a table with WHERE, but want the FK objects values to be bindable is the easiest way to just create a custom class(my table has tons of FK references).

Could you give us an example of what kind of query you are trying to write? If you are just trying to return a DataTable without creating a custom class just write your query and use the ExecuteReader which Returns an IDataReader. The IDataReader is bindable and if you need more you can just load it into a DataTable.

Related

How to query the "Props" table from Flexible Search?

Inside my code I have the primary keys of some page components in Hybris and I have to find all their attributes (properties like title, content etc.)
I can query the "Props" table using an SQL query, but I'm not sure how to find the equivalent in Flexible Search, since querying the database directly is not recommended.
Is there any other simpler way to retrieve all the properties of a component having just the primary key?
What you can do is retrieve the required component using it's primary key. Example:
select {pk} from {SimpleCMSComponent} where {pk} ='8796093056060'
Usually flexible searches are used in DAO classes(Platform example: DefaultProductDao).
When this flexible search is run by the flexible search service you get a ComponentModel. Please see below a groovy script I just created in order to exemplify how to print the ID of a Component retrieved based on its PK(In the same way by using getters you can get the title, content, etc.. ):
import de.hybris.platform.cms2.model.contents.components.SimpleCMSComponentModel;
def flexibleSearchService = spring.getBean("flexibleSearchService");
SimpleCMSComponentModel simpleCmsComponent = flexibleSearchService.search("select {pk} from {SimpleCMSComponent} where {pk} ='8796093056060'").getResult().get(0);
println(simpleCmsComponent.getUid())
I believe though that the best practice in case of CMS Components is to use their IDs instead of PK.

How to select only needed fields of objects?

I am using the Pimcore API to fetch objects.
$myObjects = new Object\MyObject\Listing();
$myObjects->load();
$myObjects->getObjects();
Works as expected. Now I want to select only a specific field of my objects, e.g. the name field.
How can I tell Pimcore to select only fields that I want? Is it even possibile through the API or do I need to use custom SQL? If so, how can I do that?
Best regards
The pimcore listing is always returning the complete set of objects matching your listing condition...
If you want a fast and easy way to only select one field of your object, I recommend to use the pimcore db class:
$db = \Pimcore\Db::get();
$fieldsArray = $db->fetchCol("SELECT `YOUR_FIELD` FROM `object_query_CLASS-ID`");
This will return you an array width all 'YOUR_FIELD' values from the object query table of your class.
To get the class ID for your query dynamically your should use:
$classId = \Pimcore\Model\Object\MyObject::classId();
Edit:
To get more than one field column, you need to use 'fetchAll' instead of 'fetchCol':
$fieldsArray = $db->fetchAll("SELECT `YOUR_FIELD`, `YOUR_FIELD_2` FROM `object_query_CLASS-ID`");

Is it possible to create a cross-database query with ServiceStack ORMLite?

Pretty much summed up in the title.
Trying to hit a table in one database and join it to a table in another database on the same server.
I would have assumed an attribute for Database that I could decorate the POCO with, but do not see one that would be appropriate.
Currently using this syntax:
var result = db.Select<Model.Dto>(
db.From<Data.Dto1>()
.Join<Data.Dto2>(d1, d2) => d1.Id == d2.Id));
There's no specific attribute for specifying an external database but in RDBMS's that support cross-database queries you should be able to use the [Schema] attribute, e.g:
[Schema("Server1.Database1.dbo")]
public class Dto { ... }

Linq to Sql using a non-column attribute property in Association attribute

I am trying to create an association between 2 linq to sql entities, say Entity A and Entity B.
A uses a non-column attribute property ( named BaseDocumentType ) and a column attribute in an Association for "ThisKey" and 2 column attributes for "OtherKey". The following is an example of my Association attribute definition...
[System.Data.Linq.Mapping.AssociationAttribute ( ... ThisKey = "BaseDocumentType, Column2" , OtherKey = "Column1,Column2" )]
When I run it I get the following error...
"Data member 'System.String BaseDocumentType' of type 'Library' is not part of the mapping for type 'A'. Is the member above the root of an inheritance hierarchy?"
How can I define the relationship using the non-column attribute property or how do I make this work?
Thanks.
The message is quite clear. LINQ to SQL translates statements to SQL and you tried to use a property that doesn't map to a column, so it can't be translated to SQL.
You'll have to retrieve the entities you want from the database then try to query them using LINQ to Objects, ie LINQ operations on the resulting lists or arrays. A better option is to rethink your design and find a way to retrieve only the data you need from the database and avoid processing the results on the client.
Linq to SQL in this case prevented you from doing something really dangerous. It could have retrieved all the data and process them using your non-column attribute but that would create an enormous performance hit. Some naive LINQ providers actually do just that. Imagine retrieving 1000 objects from the database only to find the two objects that match over this non-column attribute.

Search filter using a bean's field values

Given a JSF/EJB stack, how do I filter the contents of a dataTable listing automatically using the values of a field in a pojo/entity bean?
i.e. I have an entity bean Employee with name field having a value of "John" I would like to use this bean to filter the data table to show only records with name John, and not having to construct the where clause manually?
I use PrimeFaces' dataTable with filtering and eventually lazy-Loading. Filtering alone is done at a client level, but lazy-loading is done at a server level.
Here you can find some examples.
Both are implemented with Ajax features by PrimeFaces: on typing each character, the filters are applied and the results updated.
With PrimeFaces' lazy-loading you have also the possibility to handle by yourself the filters: on typing a character in a filter, your implementation of the filter is invoked: with a little of Criteria Builder queries you can write the WHERE conditions in a type-safe and OO way, by building an array of Predicates: this implies that you don't need to write a single line of sql code.

Resources