Invalid object name 'dbo.__MigrationHistory'
See original GitHub issueWhen debugging in Visual Studio we are getting the following Exception pretty often:
"System.Data.SqlClient.SqlException" in System.Data.dll
Invalid object name 'dbo.__MigrationHistory'.
Entity Framework is right here we don’t use ‘dbo.__MigrationHistory’ and we dont use Code First Migrations. We are only using EF for Audit.
After a little investigation it seems that one can turn off the check for ‘dbo.__MigrationHistory’ by setting
Database.SetInitializer<YourContext>(null);
according to this StackOverflow [Link:]
(https://stackoverflow.com/questions/20877039/invalid-object-name-dbo-migrationhistory-using-database-create-ef6-02-when)
is there a way to tell the
Audit.Core.Configuration.DataProvider
to use
Database.SetInitializer<YourContext>(null);
?
Or another way to stop the cause of the exception?
Heres the Code to create the audit scope
` private void SetAuditProvider(DirectDbDataAccess db)
{
Audit.Core.Configuration.DataProvider = new SqlDataProvider()
{
ConnectionString = db.ConnectionInfo.ConnectionString,
Schema = "dbo",
TableName = "Audit",
IdColumnName = "EventId",
JsonColumnName = "Data",
LastUpdatedDateColumnName = "LastUpdatedDate",
CustomColumns = new List<CustomColumn>()
{
new CustomColumn("EventType", ev => ev.EventType)
}
};
Audit.Core.Configuration.AddCustomAction(ActionType.OnScopeCreated, scope =>
{
if (!m_audit.isActive()) scope.Discard();
});
}`
heres the code to create the table:
CREATE TABLE [Audit]
(
[EventId] BIGINT IDENTITY(1,1) NOT NULL,
[InsertedDate] DATETIME NOT NULL DEFAULT(GETUTCDATE()),
[LastUpdatedDate] DATETIME NULL,
[Data] NVARCHAR(MAX) NOT NULL,
[EventType] NVARCHAR(100) NOT NULL,
CONSTRAINT PK_Event PRIMARY KEY (EventId)
)
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (3 by maintainers)
Top GitHub Comments
ok I will release a version with the first option soon
I updated this moring. works great. thank you for help and your efforts you put into Audit.net 😃