Click here to Skip to main content
15,896,063 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
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 
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 14:40
simpledeveloper9-Dec-19 14:40 
AnswerRe: The operation failed: The relationship could not be changed because one or more of the foreign-key - EF Code first Pin
simpledeveloper10-Dec-19 9:11
simpledeveloper10-Dec-19 9:11 
QuestionException: Nullable object must have a value while typecasting in a Linq query Pin
simpledeveloper4-Dec-19 10:29
simpledeveloper4-Dec-19 10:29 
AnswerRe: Exception: Nullable object must have a value while typecasting in a Linq query Pin
phil.o4-Dec-19 10:51
professionalphil.o4-Dec-19 10:51 
AnswerRe: Exception: Nullable object must have a value while typecasting in a Linq query Pin
Richard MacCutchan4-Dec-19 22:11
mveRichard MacCutchan4-Dec-19 22:11 
AnswerRe: Exception: Nullable object must have a value while typecasting in a Linq query Pin
Richard Deeming5-Dec-19 1:06
mveRichard Deeming5-Dec-19 1:06 
AnswerRe: Exception: Nullable object must have a value while typecasting in a Linq query Pin
simpledeveloper5-Dec-19 6:28
simpledeveloper5-Dec-19 6:28 
GeneralRe: Exception: Nullable object must have a value while typecasting in a Linq query Pin
Richard MacCutchan5-Dec-19 7:51
mveRichard MacCutchan5-Dec-19 7:51 
QuestionHow to connect multiple computers to the same database? Pin
SebGM252-Dec-19 14:53
SebGM252-Dec-19 14:53 
AnswerRe: How to connect multiple computers to the same database? Pin
Richard Deeming3-Dec-19 0:41
mveRichard Deeming3-Dec-19 0:41 
GeneralRe: How to connect multiple computers to the same database? Pin
Member 1468812212-Dec-19 20:12
Member 1468812212-Dec-19 20:12 
GeneralRe: How to connect multiple computers to the same database? Pin
amrinde12-Dec-19 20:34
professionalamrinde12-Dec-19 20:34 
AnswerRe: How to connect multiple computers to the same database? Pin
Maciej Los3-Dec-19 1:44
mveMaciej Los3-Dec-19 1:44 
GeneralRe: How to connect multiple computers to the same database? Pin
Richard Deeming3-Dec-19 2:07
mveRichard Deeming3-Dec-19 2:07 
PraiseRe: How to connect multiple computers to the same database? Pin
Maciej Los3-Dec-19 3:19
mveMaciej Los3-Dec-19 3:19 
GeneralOT Pin
Richard Deeming3-Dec-19 3:25
mveRichard Deeming3-Dec-19 3:25 

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.