Click here to Skip to main content
14,425,979 members

.NET Framework

 
PinnedHOW TO ANSWER A QUESTION Pin
Chris Maunder16-Jul-09 4:09
cofounderChris Maunder16-Jul-09 4:09 
PinnedHow to get an answer to your question Pin
Chris Maunder16-Jul-09 4:05
cofounderChris Maunder16-Jul-09 4:05 
QuestionMessage Closed Pin
21-Jan-20 22:16
Memberroserita020921-Jan-20 22:16 
QuestionSubtract number for each row from datagridview1 to datagridview2 and display to answer to datagridview3 Pin
percy0521-Jan-20 16:32
Memberpercy0521-Jan-20 16:32 
AnswerRe: Subtract number for each row from datagridview1 to datagridview2 and display to answer to datagridview3 Pin
Richard MacCutchan21-Jan-20 22:32
communityengineerRichard MacCutchan21-Jan-20 22:32 
QuestionGetting Error System.IO.InvalidDataException: 'End of Central Directory record could not be found Pin
simpledeveloper2-Jan-20 9:10
Membersimpledeveloper2-Jan-20 9:10 
AnswerRe: Getting Error System.IO.InvalidDataException: 'End of Central Directory record could not be found Pin
Eddy Vluggen2-Jan-20 11:29
mveEddy Vluggen2-Jan-20 11:29 
AnswerRe: Getting Error System.IO.InvalidDataException: 'End of Central Directory record could not be found Pin
Richard MacCutchan2-Jan-20 22:55
communityengineerRichard MacCutchan2-Jan-20 22:55 
QuestionMessage Closed Pin
31-Dec-19 20:09
Memberlinden george31-Dec-19 20:09 
Questionwhat is tuple in mvc Pin
Anil Sharma198326-Dec-19 6:29
professionalAnil Sharma198326-Dec-19 6:29 
AnswerRe: what is tuple in mvc Pin
Pete O'Hanlon26-Dec-19 7:38
communityengineerPete O'Hanlon26-Dec-19 7:38 
AnswerRe: what is tuple in mvc Pin
Eddy Vluggen26-Dec-19 12:42
mveEddy Vluggen26-Dec-19 12:42 
QuestionSharpGL control on MDI Childwindow: Childwindow not sizable with mouse Pin
Member 1433546425-Dec-19 6:48
MemberMember 1433546425-Dec-19 6:48 
QuestionHow to get connection string of server and connect to it? Pin
SebGM2521-Dec-19 7:01
MemberSebGM2521-Dec-19 7:01 
AnswerRe: How to get connection string of server and connect to it? Pin
Eddy Vluggen21-Dec-19 11:38
mveEddy Vluggen21-Dec-19 11:38 
QuestionMessage Closed Pin
20-Dec-19 23:51
Memberbaba ntanzi20-Dec-19 23:51 
QuestionRichTextBox Viewer Pin
Diex196819-Dec-19 5:25
MemberDiex196819-Dec-19 5:25 
AnswerRe: RichTextBox Viewer Pin
Eddy Vluggen21-Dec-19 11:41
mveEddy Vluggen21-Dec-19 11:41 
GeneralRe: RichTextBox Viewer Pin
Gerry Schmitz22-Dec-19 4:24
mveGerry Schmitz22-Dec-19 4:24 
GeneralRe: RichTextBox Viewer Pin
Diex196822-Dec-19 8:08
MemberDiex196822-Dec-19 8:08 
QuestionGet list from list of elements link and collections Pin
simpledeveloper13-Dec-19 7:13
Membersimpledeveloper13-Dec-19 7:13 
AnswerRe: Get list from list of elements link and collections Pin
Richard Deeming13-Dec-19 7:29
communityengineerRichard Deeming13-Dec-19 7:29 
GeneralRe: Get list from list of elements link and collections Pin
simpledeveloper13-Dec-19 9:24
Membersimpledeveloper13-Dec-19 9: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 7:45
Membersimpledeveloper6-Dec-19 7:45 
I am using Entity Framework Code First - I am getting the following message in deleting any of the tables data - like CaseNov, ViolationsNov and ViolationTypeNov are three tables which are to handle many to many relationships between Case-Nov, Violation-Nov and ViolationType-Nov, I am getting error messages even if I trying to delete the detailed tables like: CaseNov, ViolationsNov, ViolationTypeNov or row directly from NOV table, I am getting the similar type of message - any help please? I am using Entity Framework Code First for deleting it.
The operation failed: The relationship could not be changed because one or more of the foreign-key properties is non-nullable. When a change is made to a relationship, the related foreign-key 
property is set to a null value. If the foreign-key does not support null values, a new relationship 
must be defined, the foreign-key property must be assigned another non-null value or the unrelated 
object must be deleted.

Here is the code for deleting records any help please:
public bool Delete(NOV nov, bool performCommit = true)
{
    System.Data.Entity.DbContextTransaction dbOperation = null;
    if (performCommit)
        dbOperation = UnitOfWork.BeginTransaction();
    try
    {
        //deleting all OneToMany references to NOV
        List<ViolationTypeNOV> novRels = UnitOfWork.ViolationTypeNOVRepository
            .GetAll().Where(x => x.NOVId == nov.NOVId).ToList();

        foreach (ViolationTypeNOV o in novRels)
        {
            nov.ViolationTypeNOVs.Remove(o);
            this.UnitOfWork.ViolationTypeNOVRepository.Delete(o.ViolationTypeNOVId);
        }
        novRels.RemoveAll(x => x.NOVId == nov.NOVId);

        List<ViolationNOV> violationNOVs = UnitOfWork.ViolationNOVRepository
            .GetAll().Where(x => x.NOVId == nov.NOVId).ToList();
        foreach (ViolationNOV o in violationNOVs)
        {
            nov.ViolationNOVs.Remove(o);
            this.UnitOfWork.ViolationNOVRepository.Delete(o.ViolationNOVId);
        }
        violationNOVs.RemoveAll(x => x.NOVId == nov.NOVId);

        List<CaseNOV> caseNOVs = UnitOfWork.CaseNOVRepository
            .GetAll().Where(x => x.NOVId == nov.NOVId).ToList();
        foreach (CaseNOV o in caseNOVs)
        {
            nov.CaseNOVs.Remove(o);
            this.UnitOfWork.CaseNOVRepository.Delete(o.CaseNOVId);
        }
        caseNOVs.RemoveAll(x => x.NOVId == nov.NOVId);

        UnitOfWork.NOVRepository.Delete(nov.NOVId);

        if (dbOperation != null)
            dbOperation.Commit();

        LogHandler.LogInfo(2521, "Deleted NOV " + nov.NOVNumber);
        return true;
    }
    catch (Exception ex)
    {
        LogHandler.LogError(2523, "Commit Fail in NOV Delete", ex);
        if (dbOperation != null)
            dbOperation.Rollback();
        throw ex;
    }
}


modified 6-Dec-19 12:54pm.

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 8:29
mveGerry Schmitz6-Dec-19 8:29 

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.