Walaa,
Thank you for your reply. I am not mistaking anything. Quite the contrary. I mentioned DbCount by way of showing a different approach that I could use with the generated code. However, both are inappropriate in my situation.
Regardless of whether I do a GetMulti(Predicate) and check the count, or I just do a DbCount(), or what have you, there is way too much I/O being incurred in the server. The best solution I found to check mere existence was to set the maximum rows returned to 1, and to use GetMulti(Predicate, 1), or whichever overload that was. (I do not have the documentation in front of me).
I am sorry that I am not explaining this adequately. What we need is to merely check the existence of some rows, say, to see if a SKU has ever been used in relationship to an Order, for example.
This example would illustrate it:
Assume:
Order
SKU
OrderSKU (association table).
To see if a SKU exists on any Order, we would need a Predicate for the SKU number, and a Relations collection to show how to apply it.
Please excuse code sample errors in this forum
Dim sku As SKUEntity = New SKUEntity(3)
Dim skus As SKUCollection = New SKUCollection()
Dim predExp As PredicateExpression = New PredicateExpression(EntityType.SKU)
predExp.AddWithAnd(New FieldCompareValuePredicate(SKUFields.SKU, CompareValue, SKU.SKUNumber)
Dim rels As RelationCollection = New RelationCollection
rels.Add(SKUEntity.Relations.OrderSKUByOrderId)
rels.Add(OrderSKUEntity.Relations.SKUBySKUNumber)
If SKU.Exists(OrderPredicate, Relations) would be excellent. That would do something like this:
IF EXISTS
(
SELECT
*
FROM
dbo.Order
INNER JOIN dbo.OrderSKU ON
dbo.OrderSKU.OrderId = Order.OrderId
INNER JOIN dbo.SKU ON
dbo.SKU.SKUNumber = dbo.OrderSKU.SKUNumber
WHERE
dbo.SKU.SKUNumber = 3
)
BEGIN
RETURN 1
END
ELSE
BEGIN
RETURN 0
END
This way, the server checks for EXISTENCE, not COUNT. This is a _massive _difference. The server can stop after the first row that meets the condition. It does not have to COUNT() over millions upon millions of rows. This is why my GetMulti(Predicate, 1) works so much better than COUNT() to satisfy this case. Regardless, that feels like a hack, as much as I try to cope with it mentally.
Using GetScalar() or GetDbCount(), or what have you, is not the same as a straight EXISTS(). My feeling is that this would not be hard to do, given the generated code and being able to apply predicates and relations.
Does that explain it better? My idea is to just check existence of any rows that meet the criteria.
cardplayer