7. Fig.

What is a map, where the figure does not mean png jpeg jpg gif, nor is it a map

But rather an abstract concept, shows a relationship between entities. This relationship is generally in the database from the master table it refers to the relationship.

datacontext.savechanges () can be saved in FIG, but need to add a little shampoo (shampoo terminology here is, depending on the context may be translated into effect, special handling, etc.)

For example, you have a physical map

Book book = new Book()
{
    Title = "iOS Fundamentals",
    Author = new Author()
    {
        AuthorId = 1,
        Name = "Mark"
    },
    Categories = new List<Category>()
    {
        programmingCat, 
        new Category() { CategoryName = "iOS"},
        new Category() { CategoryName = "Swift"}
    }
};

Way to save your map should be written like this

public static void InsertOrUpdate(Book book)
{
    using(var context = new BookStore())
    {
        context.Entry(book).State = book.BookId == 0 ? 
            EntityState.Added : EntityState.Modified;
        
        context.Entry(book.Author).State = book.Author.AuthorId == 0 ? 
            EntityState.Added : EntityState.Modified;
    
        foreach (var cat in book.Categories)
        {
            context.Entry(cat).State = cat.CategoryId == 0 ? 
            EntityState.Added : EntityState.Modified;
        }
        
        context.SaveChanges();
    }
}

 

Guess you like

Origin www.cnblogs.com/nocanstillbb/p/11494937.html