IT:AD:Code First
Summary
Example
public class EFRepository : IGraphRepository<GraphVertex, int, IGraphEdge<GraphVertex>>
{
private readonly GraphContext _graphContext = new GraphContext();
public void Persist(params GraphVertex[] vertices)
{
foreach(GraphVertex vertex in vertices)
{
bool isDetached = ((int)_graphContext.Entry(vertex).State).BitIsSet((int)EntityState.Modified);
if (vertex.Id == default(int))
{
_graphContext.Vertices.Add(vertex);
}
else
{
_graphContext.Vertices.Attach(vertex);
_graphContext.Entry(vertex).State = EntityState.Modified;
}
}
_graphContext.SaveChanges();
}
}
}