My main problem lies with this error:

> 
> SqlException: The DELETE statement conflicted with the REFERENCE constraint "FK\_Predbilježba\_Seminar\_SeminarID". The conflict occurred in database "aspnet-SeminarskiRad-79DF16A9-A226-4056-9182-4A843CF2FF27", table "dbo.Predbilježba", column 'SeminarID'. The statement has been terminated.
> 
> 
> System.Data.SqlClient.SqlCommand+<>c. ExecuteDbDataReaderAsync>b\_\_122\_0(Task result)  
> 
>  DbUpdateException: An error occurred while updating the entries. See the inner exception for details.
> 
> 
> Microsoft.EntityFrameworkCore.Update.ReaderModificationCommandBatch.ExecuteAsync(IRelationalConnection connection, CancellationToken cancellationToken)
> 
> 
> 

This is class #1 

```
public class Predbilježba
{
    [Key]
    public int PredbilježbeID { get; set; }

    [Required]
    [StringLength(50, MinimumLength = 1)]
    public string Ime { get; set; }

    [Required]
    [StringLength(50, MinimumLength = 1)]
    public string Prezime { get; set; }

    [Required]
    [StringLength(50, MinimumLength = 1)]
    public string Adresa { get; set; }

    [Required]
    [StringLength(50, MinimumLength = 1)]
    public string Email { get; set; }

    [Required]
    [StringLength(13, MinimumLength = 9,)]
    public string Telefon { get; set; }

    public bool Status { get; set; }

    [DataType(DataType.Date)]
    public DateTime DatumUpisa { get; set; }

    public int? SeminarID { get; set; }

    public Seminar Seminar { get; set; }
}

```

Class #2

```
public class Seminar
{
    [Key]
    public int SeminarID { get; set; }

    [StringLength(50, MinimumLength = 3)]
    public string Naziv { get; set; }

    [StringLength(50, MinimumLength = 3)]
    public string Opis { get; set; }

    [DataType(DataType.Date)]
    public DateTime Datum { get; set; }

    public bool Popunjen { get; set; }

    public ICollection<Predbilježba> Predbilježba { get; set; }
}

```

Problem is when I call `Delete` method in the controller. But `Edit` method works, as well as the `Create` method.

This is `Delete` part of controller:

```
// GET: Seminari/Delete/5
[Authorize]
public async Task<IActionResult> Delete(int? id)
{
        if (id == null)
        {
            return NotFound();
        }

        var seminar = await _context.Seminari
            .FirstOrDefaultAsync(m => m.SeminarID == id);

        if (seminar == null)
        {
            return NotFound();
        }

        return View(seminar);
}

// POST: Seminari/Delete/5
[Authorize]
[HttpPost, ActionName("Delete")]
[ValidateAntiForgeryToken]
public async Task<IActionResult> DeleteConfirmed(int id)
{
        var seminar = await _context.Seminari.FindAsync(id);
        _context.Seminari.Remove(seminar);
        await _context.SaveChangesAsync();
        return RedirectToAction(nameof(Index));
}

private bool SeminarExists(int id)
{
    return _context.Seminari.Any(e => e.SeminarID == id);
}

```