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; }
}
}
Items model
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; }
}
}
I currently have my index built keeping ID
as primary key in both the entities. I have Neighbor_ID1
and Neighbor_ID2
as two foreign keys, however I want to make a composite key consisting of (Neighbor_ID1, Neighbor_ID2
) for uniquely identifying edges.
Can I just add [Key]
annotations for both and edit my up method to have AddForeignKeyOperations()
?
I am quite new to EF and would like to know the advantages or disadvantages of the approach.
PS: I understand that cascade delete operations with my current approach wouldn't work. Assume a connected acyclic graph topology in between the said Edges and Verteces and that I would want a many-to-many relationship ideally.