[Environment]
Windows 7 Ultra
VS 2010 Ultra
Entity Framework 4.2
Entity Framework Power Tool CTP1
[Details]:
I'm doing some exercises about EF Code-First. During doing it with local server of SQL Sever 2008 Express, the EF Power Tool can display the entity data model diagram. it works well.
After I define a connectionstring in app.config to connect a LAN server of SQL Server 2008, view the entity data model again. The EF Power Tool shows me a dialog of error HResult 0x000xxxx. By running the application, it rebuilds the tables in database as I expect.
I found a comment in the page of downloading EF Power Tool CTP1. The Devart team gets the problem like me.
http://visualstudiogallery.msdn.microsoft.com/72a60b14-1581-4b9b-89f2-846072eff19d?SRC=VSIDE
[Question]:
Is any tool like the EF Power Tool to create data model diagram with POCOs and DbContext?
How to do to fix the problem above?
THX
Unlike EF Power Tool, Devart Entity Developer allows you to create data model diagram with POCOs and DbContext at design time initially. Please take a look at this article.
Since there is the problem with usage of existing DbContext with connection string from the *.config file, you can be interested in generating Code-First fluent mapping by Devart Entity Developer.
However, if you are going to use EF Power Tool, please take a look at this article.
Devart Team
Related
How can I scaffold EF Core directly from a Visual Studio SQL Server Database Project?
Solutions such as the following are preferred:
scaffold-dbcontext -connection "provider=ssdtproject, name=myprojectname.sqlproj"
scaffold-dbcontext -ddl "ssdtprojectoutput.sql"
scaffold-dbcontext -ssdtschema "ssdtproject.dacpac"
maintained-third-party-tool myprojectname.sqlproj -EfModelGenerationParameters
That's the whole question. What follows is my situation in more detail, so that you may be able to offer alternate solutions:
Although MS acknowledges EF Core is still not production-ready, it's also now 3-4 years since EF 6 progress ceased, and EF Core is the only LINQ code-similar path forward with NETCore compatibility. Thus begins the saga titled "So you're going to be using EF Core."
This part is opinionated, but to me (based on 25+ years of enterprise software design and development experience) Code-First is an absolute non-starter. It's fine for small week-one application concepts, but there's no reasonable pattern/process/practice that I can see to integrate constraints, views, etc. Without views designed-in, real business apps end up with devs repeating logic fundamentals in LINQ expressions all over the place, littering the code with static fields to support LINQ-to-SQL queries, confusing micro-combinatory patterns using LinqKit, etc. Without constraints we end up with ten times the defensive code requirements to handle runtime errors, rapidly blossoming unit and integration tests, and demo failures become the norm. Either our object-oriented experts need to become SQL experts or the converse, and we drastically increase the difficulty of finding and properly-compensating engineers. All of these issues I pointed out in a detailed conversation four years ago with Rowan Miller (who recently left the EF team, which doesn't bode well for near-term solutions).
Model-First (the visual .edmx designer in prior EF versions) is obviously off the table, since the MS solution to this was to claim Code-First really IS Model-First, and wash their hands of it. Consequently a truly neutral, let's call it "Contract-First" for clarity, approach doesn't exist in EF Core.
So, that rant (sorry, frustrated) brings me to Database-First, and thus Scaffold-DbContext. Our DB Schema is currently a revision-controlled Visual Studio SQL Server Database Project. Aside some known issues with this, it also seems ridiculous to have to take our DB schema (currently our single-point-of-truth), rebuild a live database from it, and then back-generate code from the live database, all as part of our build process just to verify database type alignment. I'd like instead to be able to simply detect changes and regenerate my DbContext and related Entities directly from the Database Project.
SSDT Database Projects seem to make Database-like objects available in many of the UIs where normally database connections are required. That makes me think it may be a short walk to use the database schema as a source for existing tools. For example, use a metadata provider in a connection string, make a simple modification to the EF Core code, etc.
SQL Sharpener "generate[s] at design-time using SQL files as the source-of-truth (such as those found in an SSDT project", and was recommended as a solution to this problem for previous versions of EF, but it does not support EF Core.
SQLite and SQL Server Compact Toolbox just added support for generating EF Models directly from .DACPAC, but it appears to depend on the EntityFramework Reverse POCO Code First Generator for that functionality, which prominently lists "Support EF Core" on its TODO List. The primary contributor of this project confirms that incompatibility.
Help?
I was struggling with the same until I ran into the sublime EF Core Power Tools extension for Visual Studio. Its reverse engineering tool sounds just like what you need.
https://marketplace.visualstudio.com/items?itemName=ErikEJ.EFCorePowerTools
I have a Asp.Net webapi 2 system that works with sql server. I developed it using entity fraework 6.1.3 code first data models and fluent mappings with the typical workflow of add-migration/update-database. I love it.
I have a need to create the exact same software with a lighter weight db to run on a raspberry pi device. It's the disconnected version of the software that will replay/resync all of its data to the cloud version (sql server).
I realize I may need to relax some of my constraints, but starting at the extreme, I would like to target the exact same code base with something like sqlite and xcopy deploy it to my raspberry pi and run in on mono under kestrel web server.
Ideally, I'd just like to change my connection string to point to an empty sqlite db, do a update-database and have the exact same software initially run on my windows development box (and then xcopy it over).
I have read a lot about sqlite entity framework support but a) it doesn't seem to support migrations b) it doesn't seem to support fluent mapping
I could get by using a tool to convert my sql server db to sqlite (every time I change schema) and thus avoid the need to update-database. But the lack of fluent mappings would still prevent the data model to be properly mapped to the existing sqlite schema.
Does anybody have some thoughts/recommendation for sqlite that my help me accomplish my goals?
Do you have any other database recommendations that would help me accomplish my goals - for instance I looked at vistadb, but I don't think they support fluent either.
The devart sqlite driver seems to support everything I need but their examples are all old school and AFAIK they don't have one single example that is a modern code first model with fluent mappings. And even if they did fully support code first wth fluent I am concerned there would be some syntax differences and I am not sure my existing sql server targeting code would be compatible with it. I asked the question on their forums and sent an email but haven't received a response yet.
Thanks
You could consider using EF7, which is a API compatible new version of Entity Framework, that fully supports migrations and fluent mappings with SQLite. EF7 runs on .NET 4.6 and .NET Core. Depending on what features in EF6 you use, it could be an easy upgrade, in particular since you already use Code First.
http://ef.readthedocs.org/en/latest/getting-started/linux.html
I am using Entity Framework (EF) 5.0, Code First approach, and SQL Server CE 4.0 database in my application. However, I am facing a major performance problem on application start-up.
I searched on the Internet and found this article which explains which operations affect start-up performance, and one of them is view generation. So, I looked into how I could generate views at compile time and link them to EF at run-time instead of creating views at run-time. I came across Entity Framework Power Tools which provides a command to generate views through your DbContext class.
I have generated the views at compile time using Entity Framework Power Tools as described in this article. However, when I run my application with SQL Server CE it always generates the following exception:
The mapping and metadata information for EntityContainer 'DatabaseContext' no longer matches the information used to create the pre-generated views.
whereas the same application works fine with SQL Server database. So, I searched more but have not found a fix to this problem. Following are links where people have reported similar performance problems:
MSDN Blogs
Entity Framework forum on MSDN
My question is this: "Is there a workaround or solution for this application start-up performance problem?". I need to use SQL Server CE and not SQL server.
Actually EF Power tools were generating the view using the default provider SqlClient but, I needed to generate the views for SqlServerCe.4.0 provider which, I was unable to figure out why every time generated views goes out of date and finally I figured out why it was not working.
So, I just commented the DbContext constructors from my context class and, then I ran the "Generate Views" and "View Entity Data Model XML" command of EF power Tools, then EF Power Tools took the connection string from App.config otherwise it uses a default connection string that connects to Sql Server with SqlClient as provider.
So, I believe that if anybody uses any other provider like Devart's Oracle provider etc., then he/she needs to generate the views by specifying the connection string and provider information in App.config (for desktop applications) or web.config (for web applications) and comment out the DbContext constructors (or hide it from EF Power Tools using per-processor).
Is there a template or tool to generate code from the database directly? I want to use model first scenario but do not want .edmx file for mappings. There is a database with many tables and I do not want to write all the classes (I am lazy) for that. So, is there a template to generate the code and set the annotations/use fluent api for defining the relationships, etc automatically from the existing database?
This would be helpful in the following scenario as well. Say, I was using .edmx with POCOs and now I do not want the mappings in the .edmx file. I want the mappings in the code. It would be great to have a tool or a template to generate the mappings in the code from the existing database.
I am starting on learning EF 4.1. I think "Code first becomes model first in version 2 i.e. after the database is created/released (in version 1) and needs some changes". Is that really true? I'd love to hear some comments. Thanks.
Check out the 'Reverse Engineer Code First' feature of the EF Power Tools CTP1 that was just released.
For generating classes, you can use POCO t4 template generation. Have a look at this detailed link which will help you getting started. That way you will get all the classes generated.
For mapping, you can use Code-Only style for Entity Framework but generating classes and context using POCO template will have far more advantage over creating the mapping yourself. Imagine adding new tables or modifying the tables, it will involve more work. But I will certainly love to know if there is any mapping tool for that.
It is possible that you are using EF-provider Devart dotConnect for Oracle when working with Oracle database. In this case the following information will help you to choose the tool.
The first version of Entity Framework Power Tools also contained the capability of generating a Code-First model with fluent mapping from an existing database. Although useful, this functionality is limited as regards its flexibility: the developer can only set the connection string; following that, classes are generated from all database objects available to the user. That is not extremely convenient, since in Oracle, for example, numerous schemas containing hundreds and sometimes thousands of tables are available to the user.
Rather than resort to this limited functionality, the users of Devart ADO.NET providers can avail themselves of impressively robust design-time development capabilities of Entity Developer, an EF-designer delivered with Devart providers. Also possible is the choice between the Database-First approach, as provided in EF Power Tools, and the Model-First approach, within which Code-First classes are created in the EDM-designer.
When compared to EF Power Tools, the Database-First approach to the development of EF Code-First models also allows selecting objects that must be available in the model, setting naming rules for the generation of class names and properties and so on. Besides, the resulting model can be modified and improved in the designer.
To better meet developers' needs, Code-First code generation in Entity Developer both for C# and VB is based on the T4-template that is easily accessible and can be modified in feature-rich T4 Editor contained in Entity Developer.
For more information on Code-First development in Entity Developer, see "Entity Developer – EF Code First DbContext Template"
http://www.devart.com/blogs/dotconnect/index.php/entity-developer-ef-code-first-dbcontext-template.html
I'm weak on my fundamentals here, so feel free to let me know if I'm making any bizarre/false assumptions: I'm working on a project with WCF data services and due to the limitations of Odata as a querying language (e.g. no select distinct, joins are difficult, etc.), we're going to expose some service operations for common & non-trivial queries. So, I like using linqpad to get my linq code correct, and I'd like to use linqpad to target the entity framework directly (this is important: not through Odata). Is there a way I can target EF directly? Would it have to be on the same machine? What is the process?
Thanks!!!
You can target EF directly if you can point LINQPad to an assembly containing the typed ObjectContext that you created in Visual Studio. Click Add Connection and choose Entity Framework in the bottom listbox.