По сути, я есть что-то вроде:
Код: Выделить всё
public class A
{
Guid PK { get; set; }
// is an internal and external key so generically typed
string ReferenceKey { get; set; }
ICollection RelatedClassBObjs {get;set;} // this can be null
}
public class B
{
int Key { get; set }
A RelatedClassAObj { get; set; }
}
Я пытаюсь связать два класса с помощью Fluent API, делая что-то вроде
Код: Выделить всё
modelBuilder.Entity(entity => {
... //Property set up omitted
entity.HasOne(e => e.RelatedClassAObj)
.WithMany(d=>d.RelatedClassBObjs)
.HasForeignKey(e=>e.Key)
.HasPrincipalKey(d => d.ReferenceKey);
});
Код: Выделить всё
modelBuilder.Entity(entity => {
entity.HasKey(e => e.PK)
.HasName("PRIMARY");
entity.HasAlternateKey(e => e.ReferenceKey )
.HasName("reference_key");
... // extra setup omitted
});
Код: Выделить всё
JOIN B b ON b.Key = a.ReferenceKey
Код: Выделить всё
JOIN B b ON CAST(b.Key as string) = a.ReferenceKey
Любая помощь будет очень полезна. оценил.
Подробнее здесь: https://stackoverflow.com/questions/785 ... in-ef-core
Мобильная версия