How to query distinct documents that contain Unordered List properties in FileNet P8? - filenet-p8

I am trying to send a dynamically built query to FileNet 5.2 using the .Net API. The Document Class that I am trying to query has three properties in the select list that have a cardinality of Unordered List and type String. When I send over the query with the DISTINCT keyword, FileNet returns this error:
Can't select property with "distinct": RouteNumber.
Here is an example SQL statement that is getting passed to FileNet:
SELECT DISTINCT
td.DrawingNumber,
td.ProjectTitle,
td.WorkArea,
td.RouteNumber,
td.City,
td.County,
td.DrawingNumberAssignedYear,
td.Comment,
td.MajorVersionNumber,
td.IsCurrentVersion
FROM TrafficDocument AS td WITH EXCLUDESUBCLASSES
LEFT OUTER JOIN RoadwaySegment AS rwy WITH EXCLUDESUBCLASSES ON td.ID = rwy.ParentObjectID
WHERE td.IsCurrentVersion = True
AND '104' IN RouteNumber
ORDER BY td.DrawingNumber, td.TrafficPlanDiscipline
OPTIONS (TIMELIMIT 180)
I need the DISTINCT keyword because the joining document class, RoadwaySegment, is causing duplicates but it is needed in the query because their values can be filtered against as well.
So how can I achieve my goal of querying FileNet and retrieving unique results?

Is RouteNumber an orderable property? Only orderable ones are allowed for queries with DISTINCT.
DISTINCT restrictions:
A DISTINCT query can be performed only when all
of the SELECTed properties are orderable. For example, if property P1
is not orderable (Binary type, or String type with UsesLongColumn),
the following query produces an error message:
SELECT DISTINCT P1 From Object1

Related

Query to find DISTINCT between array of objects in Cosmos DB [ SQL API ]

I am using Azure Cosmos DB with SQL API and we need to find the DISTINCT values between array of objects in the same document.
I have structured the collection in the following ways
I have 2 main attribute RID and RNAME. In the first collection, I have only one document which contains all the RID and RNAME mapping in the array of objects.
"Details":[
{
"RID":"1",
"RNAME:"Car"
},
{
"RID":"1",
"RNAME:"Car"
}]
In second collection, I have multiple documents for each RID and RNAME mapping.
{
"RID":"1",
"RNAME:"Car"
}
I am using Stored procedure and I need to know which one is a good way to get DISTINCT of RNAME using stored procedure.
Using first collection, I am not sure how to query to find DISTINCT RNAME between objects in the array.
Using second collection. when I use the SQL editor, the distinct Query works but not sure how to put it in Stored procedure.
DISTINCT Values of RNAME
1.multiple documents
use sql:
select distinct c.RNAME from c
2.single document
use sql:
SELECT distinct d.RNAME FROM c
join d in c.Details

How to ignore nullable value during dynamic Linq GroupJoin on Nullable<int> Column?

We are using below code for dynamic groupjoin on SecurityID integer Column
but it includes the resultset with with nullable values.
var innerJoin = source.AsQueryable().GroupJoin(destination.AsQueryable(),
"new (outer.SecurityId as SecurityId)",
"new (inner.SecurityId as SecurityId)",
"new (outer as sources, group as destinations)").
SelectMany("destinations", "new(outer.sources as sources, inner as destinations)");
We want to avoid null values from the above query. The above query performs innerjoin and is working fine if we have joins on string columns.
Please help us to achive the above query to perform inner join on integer columns which may have 'null' values.
First of all, you can not assign null to int, instead you need to use Nullable<int> / int?. If that's the case then just filter your source using Where clause and then perform GroupJoin. I think that is the easiest way.

Linq query for one to many

My question involves MVC + Linq query. I will try to make it simple without going into the details of the Model, View, etc.. Say I have 2 tables T1 & T2. T1 holds restaurants details & T2 holds restaurants image paths. T2 rows contain restaurantID. Now if T2 has more than one rows of image paths for a Restaurant and I only need the first image path from T2 in the linq query how would I form such query? I tried to simplify the question as in fact I have 6 table joins related to the Restaurants in the query. I formed a view model which only contains the fields I want to display. I am trying to populate the view model in the controller & the query is in the controller obviously.
When I join T2 to the query, I get all the Restaurants details together with the images. But the view repeats the same Restaurant as many times as the number of table rows in T2 which is not what I want. This is the problem from the way I set the query. The query uses joins. I only need the first row from T2 while I get all from the Restaurant details. I failed to find an example for such requirement on the web so far. Your directions will be much appreciated.
Serhat Albayoglu
On your join you can use an into and then in the select you can select the FirstOrDefault
var query = from t in context.T1
join t2 in context.T2 on t.Id equals t2.RestaurantID into tgroup
select
{
t2.FirstOrDefault().path
};

How can I use Linq to join between objects and entities?

I have a collection of IDs in memory, and I would like to fetch only rows from a DB matching those IDs.
In SQL, I could either write a query like SELECT * FROM mytable WHERE id IN (1,3,5,10) or do a join between tables.
My problem is that EF can't build a query where I join my EF-data with my local array or list.
(I'm using EF4.1, but I'm guessing the problem/solution would be similar in older versions, as well as with Linq-to-SQL.)
You can use Contains() with your ID collection myIDs to generate the equivalent WHERE id IN .. query:
var results = context.mytable.Where(x => myIds.Contains(x.Id));

Entity Framework 4 generated queries are joining full tables

I have two entities: Master and Details.
When I query them, the resulting query to database is:
SELECT [Extent2]."needed columns listed here", [Extent1]."needed columns listed here"
FROM (SELECT * [Details]."all columns listed here"...
FROM [dbo].[Details] AS [Details]) AS [Extent1]
LEFT OUTER JOIN [dbo].[Master] AS [Extent2] ON [Extent1].[key] = [Extent2].[key]
WHERE [Extent1].[filterColumn] = #p__linq__0
My question is: why not the filter is in the inner query? How can I get this query? I've tried a lot of EF and Linq expressions.
What I need is something like:
SELECT <anything needed>
FROM Master LEFT JOIN Details ON Master.key = Details.Key
WHERE filterColumn = #param
I'm having a full sequential scan in both tables, and in my production environment, I have milions of rows in each table.
Thanks a lot !!
Sometimes The entity Framework does not produce the best query. You can do a few of the following to optimize.
Modify the linq statement (test with
LINQPad)
Create a stored proc and map the stored proc to return an entity
Create a view that handles the join and map the view to a new
entity

Resources