ServiceStack Ormlite - Joins on child classes

瘦欲@ 提交于 2019-12-13 08:10:01

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!