### Install GraphDiff via NuGet Package Manager Source: https://github.com/zzzprojects/graphdiff/blob/master/README.md Use this command in the Package Manager Console to install the GraphDiff NuGet package. ```powershell PM> NuGet\Install-Package RefactorThis.GraphDiff ``` -------------------------------- ### Install GraphDiff via .NET CLI Source: https://github.com/zzzprojects/graphdiff/blob/master/README.md Use this command with the .NET CLI to add the GraphDiff package to your project. ```bash > dotnet add package RefactorThis.GraphDiff ``` -------------------------------- ### Flexible API for Entity Graph Updates Source: https://github.com/zzzprojects/graphdiff/blob/master/docs/index.md This example demonstrates a more flexible API for updating entity graphs, including associated collections and owned collections. ```csharp using (var context = new TestDbContext()) { // Update the company and state that the company //'owns' the collection Contacts. context.UpdateGraph(company, map => map .OwnedCollection(p => p.Contacts, with => with .AssociatedCollection(p => p.AdvertisementOptions)) .OwnedCollection(p => p.Addresses) ); context.SaveChanges(); } ``` -------------------------------- ### WOW.js Initialization Source: https://github.com/zzzprojects/graphdiff/blob/master/docs/_layouts/default.html Initializes WOW.js for CSS3 animations. This should be called after the DOM is ready. ```javascript new WOW().init(); ``` -------------------------------- ### Google Analytics Initialization Source: https://github.com/zzzprojects/graphdiff/blob/master/docs/_layouts/default.html Initializes Google Analytics tracking for the page. Ensure your Google Analytics ID is correctly configured in site variables. ```javascript (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) })(window,document,'script','//www.google-analytics.com/analytics.js','ga'); ga('create', '{{site.ga}}', 'auto'); ga('send', 'pageview'); ``` -------------------------------- ### Table and Navigation Styling Source: https://github.com/zzzprojects/graphdiff/blob/master/docs/_layouts/default.html Applies Bootstrap table classes and highlights the active navigation link. This script runs on document ready. ```javascript $(function() { $("table").addClass("table table-bordered table-hover table-responsive-sm table-striped"); $("thead").addClass("thead-dark"); $('aside a').each(function() { if ($(this).attr('href') == '/{{page.permalink}}' || $(this).attr('href') == '{{ site.github.url }}/{{page.permalink}}') { $(this).addClass('font-weight-bold'); } }); }); ``` -------------------------------- ### Add Associated Entity (One-to-One) Source: https://github.com/zzzprojects/graphdiff/blob/master/docs/pages/tutorials/detach-associated-entity.md Demonstrates how to add a one-to-one associated entity to a parent entity using GraphDiff's AssociatedEntity() method. Ensure the associated entity is correctly mapped. ```csharp var node = new TestNode { Title = "Parent Node" }; using (var context = new TestDbContext()) { context.Nodes.Add(node); context.SaveChanges(); } // Simulate detach node.OneToOneAssociated = new OneToOneAssociatedModel { Title = "Associated Entity" }; using (var context = new TestDbContext()) { // Setup mapping context.UpdateGraph(node, map => map .AssociatedEntity(p => p.OneToOneAssociated)); context.SaveChanges(); } ``` -------------------------------- ### Scroll-to-Top Button Behavior Source: https://github.com/zzzprojects/graphdiff/blob/master/docs/_layouts/default.html Manages the visibility of a 'scroll-to-top' button based on scroll position and provides smooth scrolling functionality. ```javascript $(window).scroll(function() { if ($(this).scrollTop() >= 600) { $('#scroll-to-top').fadeIn(200); } else { $('#scroll-to-top').fadeOut(200); } }); $('#scroll-to-top').click(function() { $('body,html').animate({scrollTop : 0 }, 500); }); ``` -------------------------------- ### Add and Update Aggregated Entities Source: https://github.com/zzzprojects/graphdiff/blob/master/docs/pages/tutorials/detach-aggregated-entity.md This snippet shows how to add new associated and owned entities to a parent entity and then update the graph. Ensure entities are detached before re-attaching. ```csharp var associated = new OneToOneAssociatedModel { Title = "Associated Entity" }; var manyAssociated = new OneToManyAssociatedModel { Title = "Associated Collection Item 1" }; var node = new TestNode { Title = "Parent Node", OneToManyOwned = new List { new OneToManyOwnedModel { Title = "Owned Collection Item 1" }, new OneToManyOwnedModel { Title = "Owned Collection Item 2" }, new OneToManyOwnedModel { Title = "Owned Collection Item 3" } }, OneToManyAssociated = new List { manyAssociated }, OneToOneOwned = new OneToOneOwnedModel { Title = "Owned Entity" }, OneToOneAssociated = associated }; using (var context = new TestDbContext()) { context.OneToManyAssociatedModels.Add(manyAssociated); context.OneToOneAssociatedModels.Add(associated); context.SaveChanges(); } // Simulate detach using (var context = new TestDbContext()) { // Setup mapping node = context.UpdateGraph(node, map => map .OwnedEntity(p => p.OneToOneOwned) .AssociatedEntity(p => p.OneToOneAssociated) .OwnedCollection(p => p.OneToManyOwned) .AssociatedCollection(p => p.OneToManyAssociated)); context.SaveChanges(); } ``` -------------------------------- ### Add Associated Entities (One-to-Many) Source: https://github.com/zzzprojects/graphdiff/blob/master/docs/pages/tutorials/detach-associated-entity.md Illustrates how to add a collection of associated entities to a parent entity using GraphDiff's AssociatedCollection() method. This is useful for one-to-many relationships. ```csharp var node = new TestNode { Title = "Parent Node" }; using (var context = new TestDbContext()) { context.Nodes.Add(node); context.SaveChanges(); } // Simulate detach node.OneToManyAssociated = new List { new OneToManyAssociatedModel { Title = "Associated Entity 1" }, new OneToManyAssociatedModel { Title = "Associated Entity 2" }, new OneToManyAssociatedModel { Title = "Associated Entity 3" } }; using (var context = new TestDbContext()) { // Setup mapping context.UpdateGraph(node, map => map .AssociatedCollection(p => p.OneToManyAssociated)); context.SaveChanges(); } ``` -------------------------------- ### Handle Nested Owned Entities Source: https://github.com/zzzprojects/graphdiff/blob/master/docs/pages/tutorials/detach-owned-entity.md Manages nested owned entities by chaining the OwnedEntity method. This allows for updating entities that are owned by other owned entities. ```csharp var node = new TestNode { Title = "Parent Node" }; using (var context = new TestDbContext()) { context.Nodes.Add(node); context.SaveChanges(); } // Simulate detach node.OneToOneOwned = new OneToOneOwnedModel { Title = "Owned Entity", OneToOneOneToOneOwned = new OneToOneOneToOneOwnedModel { Title = "Nested Owned Entity" } }; using (var context = new TestDbContext()) { // Setup mapping context.UpdateGraph(node, map => map .OwnedEntity(p => p.OneToOneOwned, with => with .OwnedEntity(o => o.OneToOneOneToOneOwned))); context.SaveChanges(); } ``` -------------------------------- ### Add Owned Entity to Parent Source: https://github.com/zzzprojects/graphdiff/blob/master/docs/pages/tutorials/detach-owned-entity.md Adds a new owned entity to a parent entity. Ensure the owned entity is specified using the OwnedEntity() method during graph update. ```csharp var node = new TestNode { Title = "Parent Node" }; using (var context = new TestDbContext()) { context.Nodes.Add(node); context.SaveChanges(); } // Simulate detach node.OneToOneOwned = new OneToOneOwnedModel { Title = "Owned Entity" }; using (var context = new TestDbContext()) { // Setup mapping context.UpdateGraph(node, map => map .OwnedEntity(p => p.OneToOneOwned)); context.SaveChanges(); } ``` -------------------------------- ### Extend Entity Framework DbContext Source: https://github.com/zzzprojects/graphdiff/blob/master/docs/index.md Use this snippet to update an entity graph and specify owned collections within your Entity Framework DbContext. ```csharp using (var context = new TestDbContext()) { // Update the company and state that the company //'owns' the collection Contacts. context.UpdateGraph(company, map => map .OwnedCollection(p => p.Contacts) ); context.SaveChanges(); } ``` -------------------------------- ### Add Owned Collection to Parent Source: https://github.com/zzzprojects/graphdiff/blob/master/docs/pages/tutorials/detach-owned-entity.md Adds a collection of owned entities to a parent entity. Use the OwnedCollection() method to specify the collection during graph update. ```csharp var node = new TestNode { Title = "Parent Node" }; using (var context = new TestDbContext()) { context.Nodes.Add(node); context.SaveChanges(); } // Simulate detach node.OneToManyOwned = new List { new OneToManyOwnedModel { Title = "Owned Entity 1" }, new OneToManyOwnedModel { Title = "Owned Entity 2" }, new OneToManyOwnedModel { Title = "Owned Entity 3" } }; using (var context = new TestDbContext()) { // Setup mapping context.UpdateGraph(node, map => map .OwnedCollection(p => p.OneToManyOwned)); context.SaveChanges(); } ``` -------------------------------- ### Remove Owned Entity Source: https://github.com/zzzprojects/graphdiff/blob/master/docs/pages/tutorials/detach-owned-entity.md Removes an owned entity from the parent and the database. Set the navigational property to null to detach the owned entity. ```csharp var node = new TestNode { Title = "Parent Node", OneToOneOwned = new OneToOneOwnedModel { Title = "Owned Entity" } }; using (var context = new TestDbContext()) { context.Nodes.Add(node); context.SaveChanges(); } // Simulate detach node.OneToOneOwned = null; using (var context = new TestDbContext()) { // Setup mapping context.UpdateGraph(node, map => map .OwnedEntity(p => p.OneToOneOwned)); context.SaveChanges(); } ``` -------------------------------- ### Add Single Detached Entity Source: https://github.com/zzzprojects/graphdiff/blob/master/docs/pages/tutorials/detach-single-entity.md Add a single detached entity as a root entity to the database using DbContext.UpdateGraph(). Ensure the entity is properly instantiated before calling the method. ```csharp var node = new TestNode { Title = "Hello" }; using (var context = new TestDbContext()) { node = context.UpdateGraph(node); context.SaveChanges(); } ``` -------------------------------- ### Update Detached Graph with Owned Collection Source: https://github.com/zzzprojects/graphdiff/blob/master/docs/pages/tutorials/overview.md Use the `UpdateGraph` method to persist changes to a detached entity and its owned collection. Ensure the `DbContext` is properly disposed after saving changes. ```csharp using (var context = new TestDbContext()) { // Update the company and state that the company 'owns' the collection Contacts. context.UpdateGraph(company, map => map .OwnedCollection(p => p.Contacts) ); context.SaveChanges(); } ``` -------------------------------- ### Update Owned Entity Source: https://github.com/zzzprojects/graphdiff/blob/master/docs/pages/tutorials/detach-owned-entity.md Updates an existing owned entity when the parent entity graph is updated. The owned entity is updated if its properties have changed. ```csharp var node = new TestNode { Title = "Parent Node", OneToOneOwned = new OneToOneOwnedModel { Title = "Owned Entity" } }; using (var context = new TestDbContext()) { context.Nodes.Add(node); context.SaveChanges(); } // Simulate detach node.OneToOneOwned.Title = "Updated Owned Entity"; using (var context = new TestDbContext()) { // Setup mapping context.UpdateGraph(node, map => map .OwnedEntity(p => p.OneToOneOwned)); context.SaveChanges(); } ``` -------------------------------- ### Update Single Detached Entity Source: https://github.com/zzzprojects/graphdiff/blob/master/docs/pages/tutorials/detach-single-entity.md Update a single detached entity in the database. This involves saving the entity initially to establish its presence, modifying it, and then merging the changes using DbContext.UpdateGraph() in a new context. ```csharp var node = new TestNode { Title = "Hello" }; using (var context = new TestDbContext()) { context.Nodes.Add(node); context.SaveChanges(); } node.Title = "Updated Title"; using (var context = new TestDbContext()) { context.UpdateGraph(node); context.SaveChanges(); } ``` -------------------------------- ### Change Associated Entity (Not Saved) Source: https://github.com/zzzprojects/graphdiff/blob/master/docs/pages/tutorials/detach-associated-entity.md Shows that changes made to an associated entity's properties are not persisted by GraphDiff when updating the parent graph. Use AssociatedEntity() to map the association. ```csharp var node = new TestNode { Title = "Parent Node", OneToOneAssociated = new OneToOneAssociatedModel { Title = "Associated Entity" } }; using (var context = new TestDbContext()) { context.Nodes.Add(node); context.SaveChanges(); } // Simulate detach node.OneToOneAssociated.Title = "Updated Associated Entity"; using (var context = new TestDbContext()) { // Setup mapping context.UpdateGraph(node, map => map .AssociatedEntity(p => p.OneToOneAssociated)); context.SaveChanges(); } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.