Click here to Skip to main content
16,004,653 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
GeneralRe: Application wide information into classes in referenced DLL's Pin
A D Rosser29-Jan-20 5:17
A D Rosser29-Jan-20 5:17 
GeneralRe: Application wide information into classes in referenced DLL's Pin
Mycroft Holmes29-Jan-20 10:31
professionalMycroft Holmes29-Jan-20 10:31 
QuestionHow to export multiple image to excel in .Net core Pin
Member 1422622525-Jan-20 4:52
Member 1422622525-Jan-20 4:52 
QuestionSubtract number for each row from datagridview1 to datagridview2 and display to answer to datagridview3 Pin
percy0521-Jan-20 15:32
percy0521-Jan-20 15:32 
AnswerRe: Subtract number for each row from datagridview1 to datagridview2 and display to answer to datagridview3 Pin
Richard MacCutchan21-Jan-20 21:32
mveRichard MacCutchan21-Jan-20 21:32 
QuestionGetting Error System.IO.InvalidDataException: 'End of Central Directory record could not be found Pin
simpledeveloper2-Jan-20 8:10
simpledeveloper2-Jan-20 8:10 
AnswerRe: Getting Error System.IO.InvalidDataException: 'End of Central Directory record could not be found Pin
Eddy Vluggen2-Jan-20 10:29
professionalEddy Vluggen2-Jan-20 10:29 
AnswerRe: Getting Error System.IO.InvalidDataException: 'End of Central Directory record could not be found Pin
Richard MacCutchan2-Jan-20 21:55
mveRichard MacCutchan2-Jan-20 21:55 
Questionwhat is tuple in mvc Pin
Anil Sharma198326-Dec-19 5:29
professionalAnil Sharma198326-Dec-19 5:29 
AnswerRe: what is tuple in mvc Pin
Pete O'Hanlon26-Dec-19 6:38
mvePete O'Hanlon26-Dec-19 6:38 
AnswerRe: what is tuple in mvc Pin
Eddy Vluggen26-Dec-19 11:42
professionalEddy Vluggen26-Dec-19 11:42 
QuestionSharpGL control on MDI Childwindow: Childwindow not sizable with mouse Pin
Member 1433546425-Dec-19 5:48
Member 1433546425-Dec-19 5:48 
QuestionHow to get connection string of server and connect to it? Pin
SebGM2521-Dec-19 6:01
SebGM2521-Dec-19 6:01 
AnswerRe: How to get connection string of server and connect to it? Pin
Eddy Vluggen21-Dec-19 10:38
professionalEddy Vluggen21-Dec-19 10:38 
QuestionRichTextBox Viewer Pin
Diex196819-Dec-19 4:25
Diex196819-Dec-19 4:25 
AnswerRe: RichTextBox Viewer Pin
Eddy Vluggen21-Dec-19 10:41
professionalEddy Vluggen21-Dec-19 10:41 
GeneralRe: RichTextBox Viewer Pin
Gerry Schmitz22-Dec-19 3:24
mveGerry Schmitz22-Dec-19 3:24 
GeneralRe: RichTextBox Viewer Pin
Diex196822-Dec-19 7:08
Diex196822-Dec-19 7:08 
QuestionGet list from list of elements link and collections Pin
simpledeveloper13-Dec-19 6:13
simpledeveloper13-Dec-19 6:13 
AnswerRe: Get list from list of elements link and collections Pin
Richard Deeming13-Dec-19 6:29
mveRichard Deeming13-Dec-19 6:29 
GeneralRe: Get list from list of elements link and collections Pin
simpledeveloper13-Dec-19 8:24
simpledeveloper13-Dec-19 8:24 
QuestionThe operation failed: The relationship could not be changed because one or more of the foreign-key - EF Code first Pin
simpledeveloper6-Dec-19 6:45
simpledeveloper6-Dec-19 6:45 
AnswerRe: The operation failed: The relationship could not be changed because one or more of the foreign-key - EF Code first Pin
Gerry Schmitz6-Dec-19 7:29
mveGerry Schmitz6-Dec-19 7:29 
GeneralRe: The operation failed: The relationship could not be changed because one or more of the foreign-key - EF Code first Pin
simpledeveloper6-Dec-19 7:52
simpledeveloper6-Dec-19 7:52 
I have set the cascade delete to true - here is my migration filecode for that
public override void Up()
        {
            DropForeignKey("dbo.Violations", "NOVId", "dbo.NOVs");
            DropIndex("dbo.Violations", new[] { "NOVId" });
            CreateTable(
                "dbo.ViolationTypeNOVs",
                c => new
                    {
                        ViolationTypeNOVId = c.Int(nullable: false, identity: true),
                        NOVId = c.Int(nullable: false),
                        ViolationTypeId = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.ViolationTypeNOVId)
                .ForeignKey("dbo.NOVs", t => t.NOVId, cascadeDelete: true)
                .ForeignKey("dbo.ViolationTypes", t => t.ViolationTypeId, cascadeDelete: true)
                .Index(t => new { t.NOVId, t.ViolationTypeId }, unique: true, name: "IX_UniqueConstraintViolationTypeNOV");
            
            CreateTable(
                "dbo.CaseNOVs",
                c => new
                    {
                        CaseNOVId = c.Int(nullable: false, identity: true),
                        NOVId = c.Int(nullable: false),
                        CaseId = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.CaseNOVId)
                .ForeignKey("dbo.Cases", t => t.CaseId, cascadeDelete: true)
                .ForeignKey("dbo.NOVs", t => t.NOVId, cascadeDelete: true)
                .Index(t => new { t.NOVId, t.CaseId }, unique: true, name: "IX_UniqueConstraintCaseNov");
            
            CreateTable(
                "dbo.ViolationNOVs",
                c => new
                    {
                        ViolationNOVId = c.Int(nullable: false, identity: true),
                        NOVId = c.Int(nullable: false),
                        ViolationId = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.ViolationNOVId)
                .ForeignKey("dbo.NOVs", t => t.NOVId, cascadeDelete: true)
                .ForeignKey("dbo.Violations", t => t.ViolationId, cascadeDelete: true)
                .Index(t => new { t.NOVId, t.ViolationId }, unique: true, name: "IX_UniqueConstraintNOVViolation");
            
            AlterColumn("dbo.OneToManies", "ParentEntity", c => c.String());
            AlterColumn("dbo.OneToManies", "ChildEntity", c => c.String());
            //DropColumn("dbo.Violations", "NOVId");
        }

Still why is it not deleting it? Any help please? One more information I am able to delete the records from SSMS though - so it must be something to do with Entity Framework Code First only though.
Unit of Work Code:
public DataAccessUnitOfWork UnitOfWork { get; set; }
        public RoleManager<ApplicationRole> RoleManager { get; set; }
        public UserManager<ApplicationUser> UserManager { get; set; }
        public ApplicationUser CurrentUser { get; set; }
    
        public DomainLogicManager(DataAccessUnitOfWork unitOfWork)
        {
            this.UnitOfWork = unitOfWork;           
    
            this.RoleManager = new RoleManager<ApplicationRole>(new RoleStore<ApplicationRole>(UnitOfWork.Context));
            this.UserManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(UnitOfWork.Context));
        }

Delete method in one of the repository classes is as follows:
public bool Delete(IdT id)
        {
            T item = this.DbSet.Find(id);
            var entry = this.Context.Entry(item);
            entry.State = EntityState.Deleted;
            this.DbSet.Attach(item);
            this.DbSet.Remove(item);
            this.Context.SaveChanges();
    
            BuildMetaData(item, false, false);
            return true;
        }

Any help please - thank you.

modified 6-Dec-19 14:34pm.

GeneralRe: The operation failed: The relationship could not be changed because one or more of the foreign-key - EF Code first Pin
simpledeveloper9-Dec-19 9:12
simpledeveloper9-Dec-19 9:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.