I was getting error in this line. _set = _ORM.Set<object>();
public async void CreateEntity(BaseEntity model, String userAccount, Guid? ParentUniquId = null)
{
BaseEntity _model = null;
EntityEntry _entry = null;
try
{
//Adding the new model as shown below invokes EF's add management code.
//That is a good thing.
////Create a new model.
//GETTING ERROR HERE...
_model = this.GetNewTrackedEntity();
////Get the EF entry manager for the new model.
_entry = _ORM.Entry(_model);
//Set the client model edit mode and changedBy to their actual values.
model.ChangedBy = userAccount;
model.UniqueId = model.UniqueId == Guid.Empty ? Guid.NewGuid() : model.UniqueId;
//Set the values of the new model to the ones that were passed in.
//Commented by prasad
_entry.CurrentValues.SetValues(model);
_entry.State = Microsoft.EntityFrameworkCore.EntityState.Added;
try
{
//await _ORM.Set<Lookups.Models.Program>().AddAsync((Lookups.Models.Program)model);
var i = await _ORM.SaveChangesAsync();
String _tableName = EntityFramework.GetTableFullName(this.GetEntityType(),this._ORM);
//BELOW COMMENTED CODE ALSO NOT CREATING RECORD IN DATABASE.
// var AuditLogItem = new RM.AuditLog()
// {
// UniqueId = Guid.NewGuid(),
// ActionDate = DateTime.Now,
// ActionName = "INSERT",
// ActionPerformedBy = userAccount,
// RecordId = model.UniqueId,
// TableName = _tableName,
// TableId = model.TableId,
// ParentUniqueId = ParentUniquId
// };
// _ORM.AuditLogs.Add(AuditLogItem);
// _ORM.SaveChanges();
}
catch (Exception ex)
{
String _errMsg = ExceptionMgmt.GetExStackMsg(ex);
//Remove the entry from the change tracker.
((IObjectContextAdapter)_ORM).ObjectContext.Detach(_entry.Entity);
throw;
}
}
catch (DbEntityValidationException dbEVEx)
{
String _errMsg = ExceptionMgmt.GetDbEntValExMsg(dbEVEx);
throw new Exception(_errMsg);
}
catch (Microsoft.EntityFrameworkCore.DbUpdateException dbUEx)
{
String _errMsg = ExceptionMgmt.GetExStackMsg(dbUEx);
throw;
}
catch (Exception ex)
{
String _errMsg = ExceptionMgmt.GetExStackMsg(ex);
throw;
}
}
private BaseEntity GetNewTrackedEntity()
{
BaseEntity _model;
try
{
//GETTING ERROR HERE...
_model = (BaseEntity)EntitySet.EntityType;
return _model;
}
catch (Exception ex)
{
var msg = ex.Message;
throw;
}
}
protected Microsoft.EntityFrameworkCore.DbSet<Object> EntitySet
{
get
{
Type _type;
Microsoft.EntityFrameworkCore.DbSet<Object> _set;
_type = this.GetEntityType(); // THIS TYPE IS GETTING FROM CONTROLLER CLASS. PLEASE THIS METHOD BELOW.
_set = _ORM.Set<object>();
return _set;
}
}
protected override Type GetEntityType()
{
return typeof(Service); // Service IS ENTITY.
}