IT:AD:Code First

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();
        }
}

}

  • /home/skysigal/public_html/data/pages/it/ad/code_first/repositories.txt
  • Last modified: 2023/11/04 03:22
  • by 127.0.0.1