I would like to define an entity relationship with fluent api like this:
SELECT *
FROM tableA a
JOIN tableB b on a.itemId = ISNULL(b.idX, b.idY)
Is it even possible?
This code snippet:
modelBuilder.Entity<TableAEntity>()
.HasOne(i => i.TableBEntity)
.WithOne()
.HasForeignKey<TableAEntity>(i => i.IdX ?? i.IdY)...
produces an error:
ArgumentException: The properties expression 'i => (i.IdX ?? i.IdY)' is not valid.
The expression should represent a property access: 't => t.MyProperty'.
When specifying multiple properties use an anonymous type:
't => new { t.MyProperty1, t.MyProperty2 }'.
Parameter name: propertyAccessExpression
EDIT: The DB model:
[Table("tableA")]
class TableAEntity
{
public [Column("idX")] public string IdX { get; set; }
public [Column("idY")] public string IdY { get; set; }
public TableBEntity TableBEntity { get; set; }
}
[Table("tableB")]
class TableBEntity
{
[Key]
public int Id { get; set; }
}
Thank you