Quantcast
Channel: Michael, Author at Michael Akin
Viewing all articles
Browse latest Browse all 29

Check table configurations in EF Core 3.1

$
0
0

To check the table configurations for EF Core 3.1, I did the following and it helped identify issues.

It iterates all tables in the context and selects one row. If there is an exception, it will catch it and display some related information. It might be helpful to also capture the stack trace.

    public string LoopAllTables(bool stopAfterFirstFail)
    {
        var exceptions = new StringBuilder();
        var propertyInfos = _dbContext.GetType().GetProperties().OrderBy(o => o.Name).ToArray();
        foreach (var propertyInfo in propertyInfos)
        {
            var property = propertyInfo.GetValue(_dbContext);
            if (property is IQueryable<object> tableQ)
            {
                try
                {
                    tableQ.Take(1).Load();
                }
                catch (Exception ex)
                {
                    exceptions.AppendLine(ex.Message + Environment.NewLine + "  from " + 
                       propertyInfo.Name);
                    if (stopAfterFirstFail)
                    {
                        break;
                    }
                }
            }
        }

Viewing all articles
Browse latest Browse all 29

Trending Articles