What is the purpose of .edmx files? - entity-framework

What is the purpose of .edmx files? Reading the CSDL, SSDL, and MSL specifications, it looks to me like .edmx files are used only at design time. Are we meant to distribute it with the other edmx? It seems like we need to distribute the .ssdl and/or .csdl files instead.

EDMX is Visual Studio's "container" for all things about your Entity Data Model.
It contains all the information that is in the CSDL, SSDL, MSL, plus information about the visual layout of the tables in your Visual Studio designer surface.
The EDMX file is converted into CSDL, SSDL, MSL (typically embedded as resources in your assembly) during the build process. You definitely don't have to distribute or copy the EDMX files anywhere for the app to run.
Update: if you are more interested in a code-based approach, you should check out the code-first CTP for Entity Framework which gets by without any .edmx, .csdl/ssdl/msl files at all.

An .edmx fileis an XML file that defines a conceptual model , a storage model, and the mapping between these models. An.edmx file also contains information that is used by the ADO.NET Entity Data Model Designer (Entity Designer) to render a model graphically.

Related

Difference between ADO.NET Entity Model Template and Scaffolding

I am learning EF and found two different methods for entity model file creation.
The first method uses ADO.NET Entity Data Model Template in Visual Studio which create a .edmx file, dbcontext file and .tt file.
The second method I found at https://learn.microsoft.com/en-us/ef/core/get-started/aspnetcore/existing-db uses Scaffolding technique which uses a command like below
Scaffold-DbContext "Server=(localdb)\mssqllocaldb;Database=Blogging;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models
The second method just create the classes for the db tables and the dbcontext file but no .edmx file or .tt files metadata information being created. But the first method adds a connectionstring in app.config file with metadata information as well.
My doubt is what is the fundamental difference between these two? Are both methods acceptable in a development environment?
Your thoughts and inputs are highly appreciated.
Thanks
Peter

ADO.Net Entity Model (edmx) vs Entity Framework(v4.0 etc)

What are the benefits of using ADO.Net Entity Model and EF?
Can we use both of them together in a project. I came across an example where, the user had used both edmx and ef for his application. I am not sure what is the purpose of that.
Thanks
Edmx artifact (either in the form of a file on the disk for Model First and Database First approaches or being generated by the EF runtime - Code First approach) describes your model, your database and the mapping between these. At the moment EF always needs it to work. The only nuance is that for CodeFirst applications (or, in general, applications using DbContext) this file is generated on the fly from your classes and you don't deal with it directly while in case of Model First/Database First where you use the ObjectContext the file is on your disk and (usually) is split and embedded in your assembly.
EDIT
EF6 no longer creates and uses artifacts internally (at least for CSDL and SSDL parts). However you can still dump the model in form of EDMX using EdmxWriter.WriteEdmx

Purpose of edmgen validation? Comparing SSDL and database schemas?

Not sure what the EDMGEN is validating here
It validates the ssdl file against a live database schema looking for inconsistencies)?
Ot it only validates the internal consistency between the ssdl, csdl and msl files?
If nobody has changed manually the contents of the autogenerated ssdl, csdl and msl files is there any reason to validate them?
Is this validation the same that runs when "Validate On Build" property of the ConceptualEntityModel is set to true in visual studio?
Is there any way to check consistency between ssdl file and live database? (like new tables, diferents fields, foreign keys, etc...) A similar results like the ones provided by Redgate SQLCompare when comparing schemas...
Ot it only validates the internal consistency between the ssdl, csdl and msl files?
It validates only EDMX file - it means consistency between SSDL, MSL and CSDL.
Is this validation the same that runs when "Validate On Build" property of the ConceptualEntityModel is set to true in visual studio?
Yes
Is there any way to check consistency between ssdl file and live database?
That is not purpose of EDMGEN validation or entity framework. If you have VS Premium or Ultimate edition you can use its database tools to compare two databases - that is mostly equivalent to RedGate's SQL Compare. I'm not sure if there is any tool to compare SSDL and the real database but what you usually only need is set of your integration tests which will validate that your database still works with your model.

Entity framework by hand without designer

Maybe my google fu is sucking but I can't find any tutorial on how to use Entity framework without using the designer in Visual Studio. Is there a way to use Entity framework without the designer?
You can either use code first approach (it requires EFv4.1 or newer) where the mapping is defined in code (or by default mapping conventions) or you can create EDMX file from scratch - it is XML file.
They are two ways:
Classical (database first): You can learn about xml EF files on msdn .edmx File Overview (Entity Framework)
An .edmx file is an XML file that defines a conceptual model, a
storage model, and the mapping between these models. An .edmx file
also contains information that is used by the ADO.NET Entity Data
Model Designer (Entity Designer) to render a model graphically.
New (code first): They are a lot of resources. Here a MS code first video.

Making Entity Framework 4.0 create POCOs

When I create Entities within the Graphical view of the edmx file. All my entity classes are bundled together in the Designer file. Is there a way to make Entity Framework to create classes in separate files allowing me to have more control over my entity classes?
If you are using Visual Studio 2010, click on the design surface of the EDM Designer and select Add Code Generation Item, then select ADO.NET POCO Entity Generator. This will create a T4 Template file (*.tt) that will be used to generate your POCO classes. Every class will have it's own file.
You have to be aware of the fact that every time you make changes to your EDM and save, those classes will be re-generated and the files will be re-written, so it's better not to make any changes to them directly. Those classes are partial, so you can create new files and build up your classes without changing the initial files.