简体   繁体   English

亚音速加入问题

[英]Subsonic Join issue

For those of you who are decent with subsonic! 对于那些喜欢亚音速的人!

        TblNewsCollection col =
            new Select().From(Tables.TblNews)
                .InnerJoin(Tables.TblContent)
                .Paged(currentPage, pageSize)
                .OrderDesc(TblContent.Columns.PubDate)
                .ExecuteAsCollection<TblNewsCollection>();

The above works, no problem, but when I try to add a where clause 上面的作品,没问题,但是当我尝试添加where子句时

        TblNewsCollection col =
            new Select().From(Tables.TblNews)
                .InnerJoin(Tables.TblContent)
                .Where(TblContent.Columns.UserFK)
                .IsEqualTo(guidUserFK)
                .Paged(currentPage, pageSize)
                .OrderDesc(TblContent.Columns.PubDate)
                .ExecuteAsCollection<TblNewsCollection>();

I get this message 我收到此消息

System.InvalidCastException: Object must implement IConvertible.
at System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider)
at System.Data.SqlClient.SqlParameter.CoerceValue(Object value, MetaType destinationType) 
System.InvalidCastException: Failed to convert parameter value from a Guid to a String.

I've tried it from other fields, for example a bit field in a database it says it can't convert from bool to bit! 我从其他字段尝试过,例如数据库中的一个位字段,它说它不能从布尔转换为位!

Seems to only be an issue on where statements after joins 似乎只是关于联接后where语句的问题

我发现使用TableColumnSchema进行连接的效果更好,如上面的Northwind示例所示,而不是列名。

Northwind.CustomerCollection customersByCategory = new Select()
    .From(Northwind.Customer.Schema)
    .InnerJoin(Northwind.Order.Schema)
    .InnerJoin(Northwind.OrderDetail.OrderIDColumn, Northwind.Order.OrderIDColumn)
    .InnerJoin(Northwind.Product.ProductIDColumn, Northwind.OrderDetail.ProductIDColumn)
    .Where("CategoryID").IsEqualTo(5)
    .ExecuteAsCollection<Northwind.CustomerCollection>();

There's an example that supposedly works. 有一个据说可行的例子。 If that helps anyone help me! 如果可以的话,任何人都可以帮助我!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM