Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

entity framework delete record with foreign key constraint

public class FoodJournalEntities : DbContext
{
    public DbSet<Journal> Journals { get; set; }
    public DbSet<JournalEntry> JournalEntries { get; set; }
    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        modelBuilder.Entity<Journal>()
               .HasOptional(j => j.JournalEntries)
               .WithMany()
               .WillCascadeOnDelete(true);
        base.OnModelCreating(modelBuilder);
    }
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: unity2d movement 
Csharp :: how to set the value of a textbox textmode=date asp.net c# 
Csharp :: random string generator c# 
Csharp :: c# type of string 
Csharp :: print a file from C# 
Csharp :: c# modify dictionary in loop 
Csharp :: how to insert value to identity column using entity framwork 
Csharp :: unity button not working 
Csharp :: c# normalize value 
Csharp :: C# compare date values 
Csharp :: c# string methods 
Csharp :: ? operator 
Csharp :: set file to read only C# 
Csharp :: c# loop through datatable and update 
Csharp :: c# bool to int 
Csharp :: string c# 
Csharp :: how to redirect to another page in button clicked in asp.net c# index.cshtml 
Csharp :: fluent api 
Csharp :: unity rb.addexplosionforce 2d 
Csharp :: sealed method in c# 
Csharp :: how to mock http client c# 
Csharp :: c# access substring 
Csharp :: linq map array 
Csharp :: c sharp teleporting 
Csharp :: how to query items with any id in a list of ids linq c# 
Csharp :: C# traverseall elements in class property 
Csharp :: unity c# destroy gameobject 
Csharp :: how to check if a file is running in c# 
Csharp :: cant see my classes in inspector 
Csharp :: c# tell if a class is a child or the class itself 
ADD CONTENT
Topic
Content
Source link
Name
5+2 =