Navigation property in derived types - entity-framework

I'm new to entity framework and database design and I'm using database first approach, which in visual studio 2012 default to creating POCO classes with DbContext API. I'm trying to keep the POCO classes as lean as possible and I encountered a scenario where I want to generate two types from a single table. My problem is I want to move the navigation properties along with the foreign keys to the derived types. Does anyone know a way to solve this problem?
NOTE: I tried to post an image of what I'm trying to do but apparently I still don't have enough reputation to do that.
Edit: Thanks to whomever gave me enough reputation to post an image. The image that I'm trying to post is below.
Thanks,
Raymond

Did you ever get a solution to this? I have a similar structure. I created a super-type table in my SQL Server DB with 2 sub-type, one has a relationship to another table. EF simply set it up for me. But you should be able to do it by right-clicking on your entity and adding a new navigation item. You can then create a new Association (also by right clicking).
Regards

Related

Edit related child models in Laravel Backpack

I've just recently started using Backpack and quite like it so far.
I'm trying to figure out the best way to allow create/update for related models in Laravel Backpack.
When there is a One-to-Many or even Many-to-Many relationship, we can use field type relationship and it works. We can create new child model using the inline feature.
However, the added child model is shown as a small tag with a cross icon only. We cannot see the details of this model and cannot edit it from that screen. It would be great if we could show the existing child models as a table with edit link that opens a modal. Is there any existing component that kind of does that?
If not, how can I go about achieving this?
Alternate approach: can I use the table field and somehow modify it so that data is saved as child models instead of json? I am happy to take either approach, whichever is better.
I hope I was able to articulate what I'm trying to achieve, I'm happy to use any other approach that is there or easier.
Thanks in advance.

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!

Is there an easy way to create a database diagram in SQL Server

I'm not sure if I have worded this question properly I will explain what I am trying to acheieve further.
I am looking to create a graphical representation of an existing database showing table relationships Key relationships etc.
I have seen posts around the internet that suggest you can just go; New > Database Diagram. But I have seen nothing to this effect in Management Studio
Something similar to this:
You first need to install the Diagram Support objects. Then you all you expand the database out and right click the Database Diagram folder
If there is an database diagram drawn for the database it should be visible if you collapse DataBase Diagrams under your database. If you are trying to create one that is the way to go about it create new database diagram.

Update model from database - refresh one table

Is it possible to refresh only one entity in entity framework designer? Every time I refresh model from database, it refreshes all entities. The problem is that this mechanism doesn't recognize properly primary keys in views, so I have to correct it manually. Am I missing something?
No, you're not missing anything. When you update model using the GUI designer, the entire storage schema is regenerated. At least, that's how it works in Entity Framework 1.
I can't tell you if you can or can't do it, but I have one clue how to figure it out.
http://code.msdn.microsoft.com/EdmGen2
EdmGen2 contains source code and dll probably with functionalities from usual EdmGen.
Unfortunately I didn't have time to investigate this further. Hope this helps.

What's the easiest way to refresh Entity Model after adding/deleting DB fields?

Does anyone know what the esiest way to update the entity model after adding/deleting the fields in the database?
I am adding a few new fields to my database, then choose "Update Model from DB" and nothing happens. The model stays intact. Did anyone encounter the same problem?
Thanks for any feedback!
With EF that shipped for .net 3.5 I tend to follow the following steps:
Delete the connectionstring
Delete the model
Generate a new model
Build solution
This is perhaps not a very solid approach but it saves me time in the long run. In the future it is easier and more stable to do a refresh but I have gone from autogenerating my model to model-first.
I would definitely check out the EDM Generator which allows you to do a full generation of the model from scratch - Click here to go to the MSDN reference. It has saved me a lot of time and hope it will do the same for you.