3

I am trying to find a way to generate edmx file from query, I understand that we can update the model from database. However, in my case, we store all SQL definition scripts in a file. I need a way to generate edmx from those scripts instead of run the script file on the database and then generate edmx from database again.

1

2 Answers 2

1
+50

The reason this isn't normally possible is edmgen queries the list of DB entities and their properties. But there are no "entities" or whatever in a script, only text in a flavor of SQL. It needs to be parsed and executed (whatever form this results in) by something that understands this very flavor of SQL to create some representation of those entities so they can be inspected - i.e. at least a half-functional SQL server.

If you don't want to bother with a full MSSQL installation and DB deployment (I believe this is the primary reason for the question), you can use SQL Server Compact instead that comes bundled with every VS installation. It keeps a DB in a single file located wherever you specify (like BerkleyDB or SQLite) which you can delete afterwards.

Steve Lasker's Web Log - Creating your SQL Server Compact Edition database and schema in code explains one way to do so in .NET code. There's also a 3rd party sqlcmd counterpart for mssql compact - sqlcecmd, with which you can do the same directly from command line.

Differences Between SQL Server Compact and SQL Server lists the former's limitations. The most drastic one with respect to DDL is the absence of procedures, views and advanced indices. But they aren't used by vanilla (unlike heavily customized) Entity Framework anyway.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for pointing me in more details with the reasons that Entity Framework can't do it.
1

Unfortunately there is no straight-forward way to do this. It was briefly possible to use a database project with entity framework during the early development of VS 2012, but the feature didn't make it into the final product:

http://blogs.msdn.com/b/ssdt/archive/2012/03/09/ef-integration-removed-from-sql-server-data-tools.aspx

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.