This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
Hi there, I am using LS 4.0.1534.21185. I am attempting to translate this query into LS code: SELECT
t1.PKID AS [t1.PKID],
t1.CreatedBy AS [t1.CreatedBy],
t1.CreatedOn AS [t1.CreatedOn],
t1.Description AS [t1.Description],
t1.LockVersion AS [t1.LockVersion],
t1.UpdatedBy AS [t1.UpdatedBy],
t1.UpdatedOn AS [t1.UpdatedOn]
FROM
ContactRole t1
INNER JOIN
CustomerContact t2
ON
t1.PKID = t2.ContactRoleId
WHERE My code is as follows: Query qSearch = new Query(); qSearch.Mappings.Add qSearch.Join = Join.Inner qSearch.QueryExpression = Entity.Attribute("t2."+CustomerContact.ContactIdField) == contactId; return UOW.FindOne However the query generated is: SELECT t1.PKID AS [t1.PKID], t1.CreatedBy AS [t1.CreatedBy], t1.CreatedOn AS [t1.CreatedOn], t1.Description AS [t1.Description], t1.LockVersion AS [t1.LockVersion], t1.UpdatedBy AS [t1.UpdatedBy], t1.UpdatedOn AS [t1.UpdatedOn] FROM ContactRole t1 INNER JOIN CustomerContact t2 ON t1.PKID = t2.ContactRoleId WHERE EXISTS ( SELECT t2.* FROM CustomerContact t2 WHERE t2.ContactRoleId = t1.PKID AND t2.ContactId = 5 ) Any idea what I am doing wrong? Thanks! |
|
|
When specifying the QueryExpression, you dont want to specify "t2." + CustomerContact.ContactIdField, rather use Entity.Attribute<CustomerContact>(CustomerContact.ContactIdField). Also I presume you are specifying the type information when declaring the mappings since they look correct in the emitted SQL but this may have been lost when posting into the markdown editor?
|
|
|
Thanks Jeremy! That works perfectly. |
|