Entity Framework database-first code generation - entity-framework

This code:
ALTER DATABASE SCOPED CONFIGURATION
SET LEGACY_CARDINALITY_ESTIMATION=ON
makes my Entity Framework code generation very fast.
However I have also learned that I need to set it off my code generation completes.
Can some one explain what actually the code does? I went through google but could not find the understanding.
I am using SQL Server 2016 and Entity Framework v6

It looks like this is a known issue with new CE and the reverse engineering queries in EF. It also looks like the issue is specific to SQL 2016 and has bounced back and forth between the SQL team and the EF team.
The first fix posted was the one you mention in your post, ALTER DATABASE SCOPED CONFIGURATION SET LEGACY_CARDINALITY_ESTIMATION=ON
After this it looks like updating statistics on tables is a viable solution.
Check out this link - https://github.com/Microsoft/sql-server-samples/issues/57

Related

Data not refreshing in netTier DAL- possibly caching issue?

We're having a strange issue with one entity/data-source seemingly caching data in Data Access layer.
Basically the tables are a standard SQL Server table (SQL server 2008 R2). The code is generated the same way using the same template(NetTier 2.3.1) and Code-smith generator 6.5, there's nothing unusual about this procedure of creating DAL files.
BUT... when the tables are updated through custome procedures or outside of DAL , our web app doesn't display the latest data - sometimes it does, but sometimes it takes a few minutes for the latest data to come through. I can query the SQL database directly and see the updated data immediately, so it's not a database/lag issue.
Just to verify - I added a custom stored proc and tried getting the data that way, rather than accessing the table directly through the repository - this doesn't work either, it being an issue with the entity itself.
Any ideas? I wondered about entity caching, not sure how I can see the settings for that. Please note that we are using following tools:
Code-smith generator 6.5
NetTier 2.3.1
SQL Server 2008 R2
Project is hosted on IIS 7with .net Framework 2.0
This is an strange issue and we are facing lot of issues with caching of data. Please do reply if you have any idea ...
thanks,
Shankar..
Do you have entity tracking turned on (http://community.codesmithtools.com/nettiers/f/16/p/9639/35883.aspx)? What are your .netTiers config settings?

How to manage Entity Framework model first schema updates?

I'm using Entity Framework 5 model first. Say I've deployed the application and I'd like to upgrade an EF entity with new columns, basically adding columns to the table.
What is the best way to upgrade the existing database without losing data? For example I have a User table that I add two new columns to. If I try to script a schema change the tables will need to be dropped in order to add the new columns. Is there a way to update the tables without needing to recreate them? Thanks!
This may be a late answer but I have had the same problem and could just find one solution, there is an application that can update the model-first generated databases without losing the data.
It can directly open the model file and update the database tables.
It also installs some extensions on Visual Studio that I have not personally used but may be usable.
The name is Entity Developer and there are some editions of the application listed here:
Entity Developer Editions
The free edition is usable only for 10 entities or less that may not suit your needs but the Professional edition is usable for 30 day as a trial that may help you do the job. The only solution I could find on the net was this one.
Hope it helps you with the problem.

EF with only a subset of existing tables

I got an existing database with many tables which are accessed using stored procedures only (no O/RM). I'd like to create new tables in this database using Entity Framework and the Code First approach.
Do all the tables in my existing database need to be modelized in my Entity Framework classes? Will I be able to hand-code only the new classes I need in my DbContext? Other tables really need to stay untouched and away from O/RM for the moment.
Note: I'm going to be using the latest EF5.
As for now the Power Tools only allow you to reverse engineer all tables and views in the DB, which can be a problem if you have a big DB, with hundreds of objects, you do not want to reverse engineer.
However, I found an easy workaround for that:
Create a new technical user for the reverse engineering. To this user you only grant permission to the tables and views, that you want to be reverse engineered.
Have fun!
You are under no obligation to map any given table with EF. If you already have a database, you may want to consider reverse-engineering your database with the EF Power Tools available from Microsoft. I did this recently with a MySQL database that I had for testing purposes and it worked quite well!
If you are new to EF an advantage is that the PowerTools write a ton of code for you, which will help you get a grasp on the syntax of Code First. You will need to modify the output but it is a great start. I really believe that this approach will give you the least headache.
The EF PowerTools can be found here: http://visualstudiogallery.msdn.microsoft.com/72a60b14-1581-4b9b-89f2-846072eff19d/

Incremental Database development in Entity framework code first

How can I do incremental developments with entity framework code first database. Because if I change something i model classes it will regenerate the database which cased to loss my data already in the database. I'm using DropCreateDatabaseIfModelChanges . Is there any thing other than that to execute alter quires rather than recreating.
EF Code First Migrations would help you here, it's in alpha/CTP currently: Entity Framework Code First Migrations: Alpha, also check out the ADO.NET team blog:
The most consistent request we have heard from you since releasing EF
4.1 has been for a migrations solution for Code First that will
incrementally evolve the database schema as you model changes over
time. Today we are announcing the release of our first Community
Technical Preview (CTP) of our Code First Migrations work.
As I recall, the Microsoft docs tell you to be sure not to use DropCreateDatabaseIfModelChanges in production environments. The point of that option is to help you come up with code-based data population for your test runs. I haven't seen any tools to help with incremental changes when using code-first. Where I work, we use a database-first setup, and we create a change script for each new release that includes alter and insert statements.
incremental database development is not currently available in the current version of the codefirst framework however it is included in the roadmap for the next release which will ship with MVC 4
as of right now you would need to remove metadata tracking from the database conventions and update the database manually via scripting or using the sql tooling until this new convention is added to the framework

ASP.MVC2.0/EF4.0 site deployment/maintenance

My small team used asp.mvc 2.0/entity framework 4.0(model first approach)/Windows Server 2008r2/Sql Server 2008 r2 stack in out web site project. We've already complete developing process, and come to the web deployment stage. In this stage we are faced with the problem - ok we'll use vs2010 features for initial server/db deploy, but what we'll do in the future? Obviously some of our models can be modified after publishing in order to satisfy new conditions, and of course our server db will contains users data sets, articles etc. Is there any approach to update servers db with new db modification, without dropping db, and converting data from old instance to the new one?
Now we have found only DAC/DACPAC approach to update server db, but we don't know how to bind auto EF model generation with DAC.
May be there is exists another solution? Is there any standard way to resolve this kind of situation? Any advice?
Thanks
I'd be interested to know if you have found a solution to this yet?
Have you tried simply generating a database based on your EF model, and using a schema comparison tool such as SQL Compare to deploy changes from the EF-generated database and your target production server?