Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The Predicates system did not restore the table alias #302

Open
Garry-Gu opened this issue Aug 16, 2022 · 1 comment
Open

The Predicates system did not restore the table alias #302

Garry-Gu opened this issue Aug 16, 2022 · 1 comment

Comments

@Garry-Gu
Copy link

Garry-Gu commented Aug 16, 2022

I have an interface that will query boxtask. For the first time, I will query whether there are boxes in composite status, and for the second time, I will query the number of items of a task. When I monitor the SQL generation, I find that when count is used, the alias of the table will remain at [y_1]

PredicateGroup predicateGroup = new PredicateGroup { Operator = GroupOperator.And, Predicates = new List<IPredicate>() };
            predicateGroup.Predicates.Add(Predicates.Field<BoxTask>(f => f.BoxId, Operator.Eq, boxid));
            predicateGroup.Predicates.Add(Predicates.Field<BoxTask>(f => f.BoxSts, Operator.Eq, BoxStatus.stockin.ToString()));
            predicateGroup.Predicates.Add(Predicates.Field<BoxTask>(f => f.Status, Operator.Eq, TaskStatus.Wait.ToString()));
conn.Get<BoxTask>(predicateGroup)

This is the generated SQL:

SELECT [y_1].[TaskNo] AS [c_0], [y_1].[TaskSno] AS [c_1], [y_1].[BoxId] AS [c_2], [y_1].[BoxSts] AS [c_3], [y_1].[FromLoc] AS [c_4], [y_1].[ToLoc] AS [c_5], [y_1].[Priority] AS [c_6], [y_1].[Status] AS [c_7], [y_1].[IsCancel] AS [c_8], [y_1].[CrtDate] AS [c_9], [y_1].[FiniDate] AS [c_10], [y_1].[UpdDate] AS [c_11], [y_1].[Remark] AS [c_12], [y_1].[Msg] AS [c_13], [y_1].[Error] AS [c_14], [y_1].[IsPushWMS] AS [c_15] FROM [BoxTask] [y_1]
 WHERE (([y_1].[BoxId] = 'BSJ002') AND ([y_1].[BoxSts] = 'stockin') AND ([y_1].[Status] = 'Wait')) Execute time :7.2 ms,Start offset :107 ms,Errored :False

-------------------------------------------another sql

conn.Count<BoxTask>(Predicates.Field<BoxTask>(f => f.TaskNo, Operator.Eq, id))

This is the generated SQL:

SELECT COUNT(*) AS [Total] FROM [BoxTask]
 WHERE ([y_1].[TaskNo] = '57936d09-d933-49c6-9f20-89b4cfed394a') Execute time :6.4 ms,Start offset :1.8 ms,Errored :True

Cause error:
Cannot bind the identifier "y_1. Taskno" composed of multiple parts.

DapperExtensions:V1.7.0

@thefat32
Copy link

thefat32 commented Sep 15, 2022

Having same problem. It appears to happen randomly, once it started to happen it will continue happening in every query :/

SQL generated correctly

SELECT COUNT(*) AS "Total" FROM "travel"
WHERE (("travel"."domain" = $1) AND ("travel"."status" IN ($2, $3, $4)))

SQL generated with error:

SELECT COUNT(*) AS "Total" FROM "travel"
WHERE (("y_1"."domain" = $1) AND ("y_1"."status" IN ($2, $3, $4)))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants