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

pgsql的ToSql 字段别名添加双引号 #467

Closed
adeewu opened this issue Sep 22, 2020 · 1 comment
Closed

pgsql的ToSql 字段别名添加双引号 #467

adeewu opened this issue Sep 22, 2020 · 1 comment

Comments

@adeewu
Copy link

adeewu commented Sep 22, 2020

表结构

CREATE TABLE "public"."Untitled" (
  "PayOrderId" varchar(50) COLLATE "pg_catalog"."default" NOT NULL,
  "Money" money NOT NULL,
  "OrderTime" timestamptz(6)
);

PayOrder类

[JsonObject(MemberSerialization.OptIn), Table(Name = "pay_order", DisableSyncStructure = true)]
    public partial class PayOrder
    {
        /// <summary>
        /// 收款金额
        /// </summary>
        [JsonProperty, Column(DbType = "money")]
        public decimal Money { get; set; }

        /// <summary>
        /// 订单时间
        /// </summary>
        [JsonProperty, Column(DbType = "timestamptz")]
        public DateTime? OrderTime { get; set; }

        /// <summary>
        /// 支付Id
        /// </summary>
        [JsonProperty, Column(StringLength = 50)]
        public string PayOrderId { get; set; }
    }

查询代码

var orderSql = fsql
                .Select<PayOrder>()
                .As(nameof(PayOrder).ToLower())
                .Where(p => p.Status == 1)
                .ToSql(p => new
                {
                    p.PayOrderId,
                    p.Money,
                    p.OrderTime
                }, FreeSql.FieldAliasOptions.AsProperty);

生成sql语句

SELECT payorder."PayOrderId" PayOrderId, payorder."Money" Money, payorder."OrderTime" OrderTime 
FROM "pay_order" payorder 
WHERE (payorder."Status" = 1)

pgsql是区分大小写的,故sql语句中payorder."PayOrderId" PayOrderId的别名PayOrderId实际需要加上双引号,不然会在后续的查询中因为大小写导致无法找到PayOrderId

@2881099
Copy link
Collaborator

2881099 commented Oct 10, 2020

感谢反馈,问题是否得到解决

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