Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I write a test to verify Entity Framework Database First Model
    text
    copied!<p>I have a Entity Framework Database First Model. </p> <p>I want to write a MSTest/nUnit test to verify that all the Stored procs and tables that are defined in my edmx model are still valid on the database.</p> <p>With a large team of developers some only working on stored procedures and other in c# I would like to run an integration test to validate/verify the EF models in the project.</p> <p>I had a test in Linq2Sql to look for an attribute that is common on the stored procedure calls then it ran a SQL Query to verify the stored procedure still exists. I've now upgraded to EF6 and I want to keep a similar sanity check in the build.</p> <p>This is what I have so far. </p> <pre><code> var list = context.MetadataWorkspace.GetItems&lt;EntityType&gt;(DataSpace.CSpace); var badSp = new List&lt;string&gt;(); foreach (var table in list) { if (!DoesTableExist(dbContext, table)) { badSp.Add(table.Name); } } if (badSp.Any()) { var retval = new StringBuilder(); retval.AppendLine("The Following Objects do not exist in the database but do not exist the " + dbContext.GetType().Name + ".edmx, they may be obsolete"); badSp.Sort(); foreach (var sp in badSp) { retval.AppendLine(sp); } Assert.Fail(retval.ToString()) } </code></pre> <p>Some issues I've come up with is this doesn't tell me if a table is in a different schema. Schema is returning null. I have tables in multiple schemas.</p> <p>I also want to do a similar test to verify tables and views, they're in different schemas also. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload