using System.ComponentModel.DataAnnotations;
namespace exmapleNameSpace.DTO
{
public class Edges
{
public long Id { get; set; }
[Required]
public string NameEdge;
[Required]
public Item Neighbor_ID1 { get; set; }
[Required]
public bool ID1isFile { get; set; }
[Required]
public Item Neighbor_ID2 { get; set; }
[Required]
public bool ID2isFile { get; set; }
}
}
物品模型
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace exampleNameSpace.DTO
{
public class Item
{
public long Id { get; set; }
[Required]
[StringLength(100)]
public string Name { get; set; }
[Required]
public bool isFolder { get; set; }
[Required]
public bool isFile { get; set; }
[RegularExpression(@"\w.([a - z]|[A-Z])")]
[StringLength(100)]
public string extension { get; set; }
[Required]
[StringLength(100)]
public string parentPath { get; set; }
[Required]
public bool isEmpty { get; set; }
}
}
我目前已建立索引,并在两个实体中都将ID
作为主键。我有Neighbor_ID1
和Neighbor_ID2
作为两个外键,但是我想制作一个由(Neighbor_ID1, Neighbor_ID2
)组成的复合键,用于唯一地标识边缘。
我可以为两者都添加[Key]
批注并编辑up方法以具有AddForeignKeyOperations()
吗?
我对EF还是很陌生,想知道这种方法的优缺点。
PS:我了解使用我当前的方法进行级联删除操作不起作用。假设在上述Edges和Verteces之间建立连接的非循环图拓扑,并且理想情况下,我希望建立多对多关系。