Question

I'm trying to save an entity to my database using this code:

    public void Add(object entity)
        {
            DbContext.Entry(entity).State = System.Data.EntityState.Added;
            DbContext.SaveChanges();
        } 

I tested and if something is wrong (e.g. a field of the entity is null that can't be null in the datbase) it gives an error. I filled in all the necesarry fields and called this code. It did not give an error. However, the entity also didn't get added to the database. How can I find out where DbContext.SaveChanges(); goes wrong without an error message?

Below is the code that calls the Add() function.

  public void StoreElectronicSignatureType(ElectronicSignatureTypeModel model)
    {
        var RSA = new System.Security.Cryptography.RSACryptoServiceProvider();
        var parameters = RSA.ExportParameters(false);
        model.modulus = Convert.ToBase64String(parameters.Modulus);
        model.exponent = Convert.ToBase64String(parameters.Exponent);
        model.privatekey = RSA.ToXmlString(true);

        ElectronicSignatureType electronicSignatureType = new ElectronicSignatureType();
        Entity entity =  GetEntity(model.entity);
        electronicSignatureType.Entity = entity;
        electronicSignatureType.HashAlgorithm = model.hashAlgorithm;
        electronicSignatureType.Exponent = model.exponent;
        electronicSignatureType.Modulus = model.modulus;
        electronicSignatureType.Version = model.version;
        //electronicSignatureType.EntityId = entity.EntityId;
        electronicSignatureType.PrivateKey = StrToByteArray(model.privatekey);
        Add(electronicSignatureType);
    }

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top