问题
I'm using the latest ServiceStack Ormlite (v4.0.23), which provides new join support for joining on multiple columns.
My entities all inherit from a BaseEntity:
public class BaseEntity : IBaseEntity
{
[AutoIncrement]
[PrimaryKey]
public long Id { get; set; }
public DateTime Created { get; set; }
public DateTime Updated { get; set; }
public DateTime? Deleted { get; set; }
public bool IsDeleted { get; set; }
}
Say I have 2 entities, UserEntity and AnswerEntity, which inherit from this base class. When using the JoinSqlBuilder in v4.0.19 I could join these using something like this:
var joinBuilder = new JoinSqlBuilder<AnswerEntity, UserEntity>();
joinBuilder = joinBuilder.Join<AnswerEntity, UserEntity>(
l => l.UserId,
r => r.Id,
x => new { x.Id, x.AnswerValue, x.QuestionId, x.Created, x.Updated, x.Deleted, x.IsDeleted },
null,
lx => lx.IsDeleted == false,
rx => rx.IsDeleted == false);
After updating, I get the error:
MySql.Data.MySqlClient.MySqlException : Unknown column 'BaseEntity.IsDeleted' in 'where clause' at MySql.Data.MySqlClient.MySqlStream.ReadPacket() at MySql.Data.MySqlClient.NativeDriver.GetResult(Int32& affectedRow, Int64& insertedId)...
Using the new join support, I get the same error:
expression.Join<AnswerEntity, UserEntity>((l, r) => l.UserId == r.Id);
expression.Where<AnswerEntity>(x => x.IsDeleted == false);
回答1:
Should now be resolved in this commit that's available from v4.0.23+ of ServiceStack that's currently available on MyGet. If you have existing v4.0.23 packages from MyGet installed it will need to be uninstalled first to be able to pull down the updated packages.
来源:https://stackoverflow.com/questions/24431135/servicestack-ormlite-joins-on-child-classes