Add SQL Server extended properties to EF 4.0 model - entity-framework

Hi
Is there a way to make EF model automatically fetch SQL Server extended property into model? I've read about POCO, but I'm a little confused since it states that you should turn automatic code generation off. If you do that, does your model still update automatically when you add new objects? and how should I update my model so it gets the extended properties for each object(table or column) automatically and sets it in the model?

That's where T4 comes in. You turn off the automatic generation, and can choose a template you want for the objects(templates also generate the objects but according to your requirements). You can use already existing templates, or create your own. To add those templates, just double click on the .edmx, then right click on window, and Add Code Generation Item.

Related

Can I set the data source for a combo box in an Entity Framework Core forms application at design time?

I feel so stupid.
I'm trying to create a simple Windows Forms application using Visual Studio 2022, .Net Core and Entity Framework. I am using the database-first approach. I have a simple database and a set of classes created from the the database by EF Core Power Tools's reverse engineering feature. I am trying to create a form that will manage vendors. I have a table named "vendors" with fields named "name" and "address". (That's enough for now.) EF Core Power Tools gave me a context class that I renamed to ForhpContext and a Vendors class.
On my form I have a combo box that I expect to contain the names of all of the vendors in my table, and a text box that will display the address of the selected vendor.
In the form design window, I can select the combo box and in its properties window, click the down arrow for the Data Source property. I get a little empty window with a link labeled "Add new Object Data Source..." When I click on that, I get a form labeled "Add and update object data sources". The form has an empty text box labeled "Filter" and a large box labeled Data Source Types. What do I do with this form? Can this form use any of the classes that were generated for me by Entity Framework? Is it possible to set up my EF data sources for the combo box and the text box at design time, or do I have to wait until run time and set them up in my Form Load event handler?
Is there a good book you can recommend that will teach me how to use EF in windows forms applications?

Does EF Core 3.1 support use of SQL Views inside of code-first DbContext?

I currently have an ASP.NET Core project using EF 3.1. I would like to use Code-First to manually build most of my entities, but there is also a linked server I need to incorporate data from as well. I need to figure out how to create an entity model that is the result of this view (that includes a left join from a code-first table I have already migrated). During my research thus far, it seems that since EF3 there is support for views inside of Scaffold-DbContext, but my concern is I would only want to scaffold this single view, but still access everything inside the same DbContext I am already using. I don't want to hack things together, so please let me know how you would accomplish such a task in your project. Thanks for your help!
Looks like I was able to figure this out after all. The steps I did are as follows, but please correct me if you know a better or more accepted way.
Selected the SQL view into a new table so I could generate a create script off of it.
Copied the create script into the class creation tool over at https://codverter.com/src/sqltoclass so didn't have to manually convert 20+ columns and types to class properties.
Copied the generated properties into a new model class named after the SQL view
Added a new DbQuery under my existing DbSets in my DbContext class. (It does seem like DBQuery is deprecated, but I don't see another way around using it currently) and named it the same as my SQL view.
Scaffolded a new controller off the SQL views model class and navigated to the generated index page to verify data could be seen. (it worked!)
Let me know if you have any better ideas on how I came to this solution!

Entity Framework: Added view appears in Model Browser but not Solution Explorer

I have a project which uses Entity Framework. I've added a view from my SQL Server database to the model using the Model Browser in Visual Studio 2012 such that it appears under the following items:
Entity Types under my model.
Entity Container, Entity Sets
.Store, Tables / Views
However, I can't access it from my code.
Back in Solution Explorer, under the Models folder, the view does not appear anywhere under the EDMX file for my model (though it DOES appear in the diagram).
I can not seem to find any practical way to add the view to my data model such that it is usable. Ultimately, I want to reference it via the entities object so I can select data from it.
Every Entity in EF should have unique identifier. Try to select a key column in view and then try to add view. View should be available to you

Creating entity diagrams from code first classes

I was just reading Asp.net MVC3 tutorials (Models (Data))
On this page tutorial 4 of 10 on the ASP.NET website, it is shown that an entity diagram is created from code first classes. How to generate them?
This can be done very easily by using the Class Diagram. Add New Item > Class Diagram. Then drag and drop your code first classes into the diagram from the solution explorer.
A Class Diagram is OK, but it doesn't automatically show the relationships between classes. The slickest way that I have used is Entity Framework Power Tools. Their description of the tool:
When right-clicking on a C# project, the following context menu function is supported: 1) Reverse Engineer Code First - Generates POCO classes, derived DbContext and Code First mapping for an existing database.
Assuming your schema has been created from the Code First classes you can reverse the db into a an edmx to visualise the Model. Any classes generated from this obviously won't be related to your Code First classes though.
Create a copy of your project. Open the copy and add a new item/ADO.NET Entity Data Model. Edit the diagram for layout and print to a .pdf file. Delete the copy of the project.
Anytime you make a change you will have to re-create the diagram and edit the layout, but I can usually get through the whole process in about 15 minutes.

iPhone Core Data Generated Model Files and Custom Code

After I've generated the interface/implementation files for entities of a model file in XCode, I've not found a way to keep any custom code (validation methods, etc...) I've added to those generated files, given the scenario where I've added an attribute to a model entity and need to re-generate the interface/implementation files. Does anyone know of a way to make this happen? I've just been doing the copy/paste shuffle, but there has to be a better way.
Assuming that you're only talking about adding methods, and not new instance variables, I'd recommend using Objective C categories to add additional behavior to your model classes. Here's a blog post along the same lines.
Use mogenerator, which uses the Generation Gap design pattern to prevent your customizations from being overwritten when the code is re-generated.