Код: Выделить всё
internal abstract class GraphNodeModel
{
public Guid Id { get; }
public Guid TypeId { get; }
public virtual GraphNodeTypeModel? Type { get; }
public List Attributes { get; init; } = [];
public List Relations { get; init; } = [];
protected GraphNodeModel(Guid typeId)
{
TypeId = typeId;
}
public class Configurator : IEntityTypeConfiguration
{
public void Configure(EntityTypeBuilder builder)
{
builder
.ToTable("graph_nodes")
.UseTptMappingStrategy();
builder.Property(n => n.Id)
.HasColumnName("graph_node_id")
.HasValueGenerator();
builder.Property(n => n.TypeId)
.HasColumnName("graph_node_type_id");
builder.HasOne(n => n.Type)
.WithMany()
.HasForeignKey(n => n.TypeId)
.OnDelete(DeleteBehavior.Restrict);
builder.HasMany(n => n.Attributes)
.WithOne()
.HasForeignKey(a => a.GraphNodeId);
}
}
}
< /code>
и отношения: < /p>
internal class GraphRelationModel
{
public Guid Id { get; init; }
public Guid NodeAId { get; init; }
public virtual GraphNodeModel? NodeA { get; init; }
public Guid NodeBId { get; init; }
public virtual GraphNodeModel? NodeB { get; init; }
public Guid RelationTypeId { get; init; }
public virtual RelationTypeModel? RelationType { get; init; }
public Dictionary Attributes { get; } = [];
public class Configurator : IEntityTypeConfiguration
{
public void Configure(EntityTypeBuilder builder)
{
builder
.ToTable("graph_relations");
builder.HasOne(r => r.NodeA)
.WithMany();
builder.HasOne(r => r.NodeB)
.WithMany();
builder.Property(r => r.Id)
.HasColumnName("graph_relation_id")
.HasValueGenerator();
builder.Property(r => r.NodeAId)
.HasColumnName("graph_node_A_id");
builder.Property(r => r.NodeBId)
.HasColumnName("graph_node_B_id");
builder.Property(r => r.RelationTypeId)
.HasColumnName("relation_type_id");
builder.Property(r => r.Attributes)
.HasConversion(
dictionary => JsonSerializer.SerializeToDocument(dictionary, JsonSerializerOptions.Default),
jsonDocument => jsonDocument.Deserialize(JsonSerializerOptions.Default) ?? new());
}
}
}
< /code>
Идея здесь состоит в том, чтобы иметь отношения между узлами. Отношение отображения определена в GrapheralationModel Я обнаружил, что коллекция в GraphNodemodel является причиной создания свойства теневого и ключа FORGEIN в GraphrelationModel
. class = "lang-cs prettyprint-override"> b.Property("GraphNodeModelId")
.HasColumnType("uuid")
.HasColumnName("graph_node_model_id");
b.HasIndex("GraphNodeModelId")
.HasDatabaseName("ix_graph_relations_graph_node_model_id");
< /code>
Как предотвратить генерацию свойств тени? Могу ли я как -то настроить это свойство?
Подробнее здесь: https://stackoverflow.com/questions/796 ... n-there-ca
Мобильная версия