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

子查询报错 是因为Type关键字吗? #1118

Closed
zhangkeyuan opened this issue May 24, 2022 · 13 comments
Closed

子查询报错 是因为Type关键字吗? #1118

zhangkeyuan opened this issue May 24, 2022 · 13 comments

Comments

@zhangkeyuan
Copy link

zhangkeyuan commented May 24, 2022

image

使用.Where(o => o.ActivityType == ac.Type)报错
版本号:3.2.640

var activityPeopleCountList = _fsql.Select<SalesmanActivityConfig>() .Where(a => a.SalesmanId == req.SalesmanId) .ToList(a => new ActivityPeopleCountModel { Type = a.Type, Count = _fsql.Select<SalesmanActivityOrder>() .Where(o => o.SalesmanId == a.SalesmanId) .Where(o => a.Type == o.ActivityType)//报错ArgumentException: Requested value 'a.Type' was not found. //.Where("o.ActivityType = a.Type", null)//正常 .Where(o => o.PayStatus == SalesmanActivityOrderPayStatusEnum.YiWanCheng) .WhereIf(req.StartTime.HasValue, o => o.AddTime.Between(req.StartTime.Value, req.EndTime.Value)) .Count(), });

@zhangkeyuan
Copy link
Author

使用 .Where("o.ActivityType = a.Type", null)正常

@zhangkeyuan
Copy link
Author

微信截图_20220524155412

@2881099
Copy link
Collaborator

2881099 commented May 24, 2022

[Fact]
        public void PropertyType()
        {
            var fsql = g.mysql;

            var item = new issues1118_01 { Type = "xxx" };
            var list1 = fsql.Select<issues1118_01>()
                .Where(o => o.Type == item.Type)
                .ToList();
        }

        public class issues1118_01
        {
            public int id { get; set; }
            public string name { get; set; }
            public string Type { get; set; }
        }

测试正常

@zhangkeyuan
Copy link
Author

[Fact]
        public void PropertyType()
        {
            var fsql = g.mysql;

            var item = new issues1118_01 { Type = "xxx" };
            var list1 = fsql.Select<issues1118_01>()
                .Where(o => o.Type == item.Type)
                .ToList();
        }

        public class issues1118_01
        {
            public int id { get; set; }
            public string name { get; set; }
            public string Type { get; set; }
        }

测试正常

那会是什么原因呀

@zhangkeyuan
Copy link
Author

[Fact]
        public void PropertyType()
        {
            var fsql = g.mysql;

            var item = new issues1118_01 { Type = "xxx" };
            var list1 = fsql.Select<issues1118_01>()
                .Where(o => o.Type == item.Type)
                .ToList();
        }

        public class issues1118_01
        {
            public int id { get; set; }
            public string name { get; set; }
            public string Type { get; set; }
        }

测试正常

那会是什么原因呀

是在子查询里面哦,外面查询没问题的

@2881099
Copy link
Collaborator

2881099 commented May 24, 2022

[Fact]
public void PropertyType()
{
    var fsql = g.mysql;

    var item = new issues1118_01 { Type = "xxx" };
    var list1 = fsql.Select<issues1118_01>()
        .ToList(ac => new {
                
            count = fsql.Select<issues1118_01>().Where(o => o.Type == ac.Type).First(o => o.name)
        });
}

public class issues1118_01
{
    public int id { get; set; }
    public string name { get; set; }
    public string Type { get; set; }
}

也没问题哦,试试把 ac 改名为 a

@zhangkeyuan
Copy link
Author

image
改成a还是报错

@2881099
Copy link
Collaborator

2881099 commented May 24, 2022

打印 SQL,正常吗

@zhangkeyuan
Copy link
Author

image
直接赋值也没问题

@2881099
Copy link
Collaborator

2881099 commented May 24, 2022

他是提示找不到 a.`Type`,SalesmanActivityConfig 这个表

@zhangkeyuan
Copy link
Author

打印 SQL,正常吗

image
换个顺序又提示ActivityType不存在了,表里是有这个字段的

@zhangkeyuan
Copy link
Author

   [JsonObject(MemberSerialization.OptIn), Table(Name = "salesman_activity_config", DisableSyncStructure = true)]
public partial class SalesmanActivityConfig
{
    /// <summary>
    ///<para>    </para>
    /// </summary>
    [JsonProperty, Column(Name = "Id", DbType = "char(32)", IsNullable = false, IsPrimary=true)]
    public string Id { get; set; }
 
    /// <summary>
    ///<para>推销员Id    </para>
    /// </summary>
    [JsonProperty, Column(Name = "SalesmanId", DbType = "char(32)", IsNullable = false)]
    public string SalesmanId { get; set; }
 
    /// <summary>
    ///<para>洗车卡业务类型:0=自助卡 1=自动卡 2=通用卡[BaseCardBussinessType]    </para>
    /// </summary>
    [JsonProperty, Column(Name = "Type", DbType = "int", IsNullable = false)]
    public BaseCardBussinessType Type { get; set; }
 
    /// <summary>
    ///<para>收益    </para>
    /// </summary>
    [JsonProperty, Column(Name = "DivideAmount", DbType = "decimal(10,2)", IsNullable = false)]
    public decimal DivideAmount { get; set; }
 
    /// <summary>
    ///<para>    </para>
    /// </summary>
    [JsonProperty, Column(Name = "AddTime", DbType = "datetime", IsNullable = false)]
    public DateTime AddTime { get; set; }
 
    /// <summary>
    ///<para>    </para>
    /// </summary>
    [JsonProperty, Column(Name = "UpdateTime", DbType = "datetime", IsNullable = true)]
    public DateTime? UpdateTime { get; set; }
 
}

@zhangkeyuan
Copy link
Author

[JsonObject(MemberSerialization.OptIn), Table(Name = "salesman_activity_order", DisableSyncStructure = true)]
public partial class SalesmanActivityOrder
{
    /// <summary>
    ///<para>    </para>
    /// </summary>
    [JsonProperty, Column(Name = "Id", DbType = "char(32)", IsNullable = false, IsPrimary = true)]
    public string Id { get; set; }

    /// <summary>
    ///<para>推销员活动配置Id    </para>
    /// </summary>
    [JsonProperty, Column(Name = "SalesmanActivityConfigId", DbType = "char(32)", IsNullable = false)]
    public string SalesmanActivityConfigId { get; set; }

    /// <summary>
    ///<para>洗车卡业务类型:0=自助卡 1=自动卡 2=通用卡[BaseCardBussinessType]    </para>
    /// </summary>
    [JsonProperty, Column(Name = "ActivityType", DbType = "int", IsNullable = false)]
    public BaseCardBussinessType ActivityType { get; set; }

    /// <summary>
    ///<para>推销员Id    </para>
    /// </summary>
    [JsonProperty, Column(Name = "SalesmanId", DbType = "char(32)", IsNullable = false)]
    public string SalesmanId { get; set; }

    /// <summary>
    ///<para>用户Id    </para>
    /// </summary>
    [JsonProperty, Column(Name = "AccountId", DbType = "char(32)", IsNullable = false)]
    public string AccountId { get; set; }

    /// <summary>
    ///<para>订单编号    </para>
    /// </summary>
    [JsonProperty, Column(Name = "OrderNo", DbType = "varchar(100)", IsNullable = false)]
    public string OrderNo { get; set; }

    /// <summary>
    ///<para>支付金额    </para>
    /// </summary>
    [JsonProperty, Column(Name = "PayAmount", DbType = "decimal(10,2)", IsNullable = false)]
    public decimal PayAmount { get; set; }

    /// <summary>
    ///<para>支付方式  0、余额支付 1、微信支付 2、支付宝 99、无    </para>
    /// </summary>
    [JsonProperty, Column(Name = "PayMethod", DbType = "int", IsNullable = false)]
    public SalesmanActivityOrderPayMethodEnum PayMethod { get; set; }

    /// <summary>
    ///<para>支付状态:1、待付款,5、已完成,10、关闭,15、退款中,20、退款完成    </para>
    /// </summary>
    [JsonProperty, Column(Name = "PayStatus", DbType = "int", IsNullable = false)]
    public SalesmanActivityOrderPayStatusEnum PayStatus { get; set; }

    /// <summary>
    ///<para>支付时间    </para>
    /// </summary>
    [JsonProperty, Column(Name = "PayTime", DbType = "datetime", IsNullable = true)]
    public DateTime? PayTime { get; set; }

    /// <summary>
    ///<para>是否已激活    </para>
    /// </summary>
    [JsonProperty, Column(Name = "IsActivated", DbType = "bit(1)", IsNullable = false)]
    public bool IsActivated { get; set; }

    /// <summary>
    ///<para>激活时间    </para>
    /// </summary>
    [JsonProperty, Column(Name = "ActivatedTime", DbType = "datetime", IsNullable = true)]
    public DateTime? ActivatedTime { get; set; }

    /// <summary>
    ///<para>购买的365年卡Id    </para>
    /// </summary>
    [JsonProperty, Column(Name = "CardOrderId", DbType = "char(32)", IsNullable = true)]
    public string CardOrderId { get; set; }

    /// <summary>
    ///<para>    </para>
    /// </summary>
    [JsonProperty, Column(Name = "AddTime", DbType = "datetime", IsNullable = false)]
    public DateTime AddTime { get; set; }

    /// <summary>
    ///<para>    </para>
    /// </summary>
    [JsonProperty, Column(Name = "UpdateTime", DbType = "datetime", IsNullable = true)]
    public DateTime? UpdateTime { get; set; }
}

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

3 participants