Skip to content

Commit

Permalink
Show proper error message if DbContext could not edited. Fixes #140
Browse files Browse the repository at this point in the history
  • Loading branch information
prafullbhosale committed Aug 26, 2016
1 parent 202d716 commit 688740e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 17 deletions.
Expand Up @@ -17,7 +17,6 @@
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.VisualStudio.Web.CodeGeneration.DotNet;


namespace Microsoft.VisualStudio.Web.CodeGeneration.EntityFrameworkCore
{
public class EntityFrameworkServices : IEntityFrameworkService
Expand Down Expand Up @@ -182,7 +181,13 @@ public async Task<ContextProcessingResult> GetModelMetadata(string dbContextFull
c =>
{
var oldTree = c.SyntaxTrees.FirstOrDefault(t => t.FilePath == addResult.OldTree.FilePath);
Debug.Assert(oldTree != null);
if (oldTree == null)
{
throw new InvalidOperationException(string.Format(
MessageStrings.ModelTypeCouldNotBeAdded,
modelTypeSymbol.FullName,
dbContextFullTypeName));
}
return c.ReplaceSyntaxTree(oldTree, addResult.NewTree);
},
out dbContextType,
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Expand Up @@ -135,6 +135,9 @@
<data name="FailedToEditStartup" xml:space="preserve">
<value>Scaffolding failed to edit Startup class to register the new Context using Dependency Injection.</value>
</data>
<data name="ModelTypeCouldNotBeAdded" xml:space="preserve">
<value>Could not add Model type '{0}' to DbContext '{1}'. Please make sure that '{1}' has a DbSet property for '{0}'.</value>
</data>
<data name="ModelTypeNotFound" xml:space="preserve">
<value>Could not get the reflection type for Model : {0}</value>
</data>
Expand Down

0 comments on commit 688740e

Please sign in to comment.