I would like to implement a simple WPF with a datagrid and a save button.
when I click save button it will accept changes (row edit,cell edit, new row, delete etc)
I tried RowEditHandler and CollectionChange event using observable collections. But I couldnt get a soluton. Can anyone please show me a simple way.
Using dataset (xsd), I was able to achive that simpy by sending datacontext of grid to dataset and using update function.
thanks for help
The ADO.NET team blog has an example how to bind a Entity Framework Code-First model to a WPF DataGrid which supports adding, deleting and editing entities in the grid and finally saving all changes. It is focussed on a Master-Details scenario but should with a few modifications also work in your even simpler case with only a single DataGrid:
http://blogs.msdn.com/b/adonet/archive/2011/03/08/ef-feature-ctp5-code-first-model-with-master-detail-wpf-application.aspx
The example is based on EF CTP5 but it will most likely also work without changes with the new EF 4.1 RC version.
The ADO.NET team example uses code-behind files and events. If you prefer to strictly work with the MVVM approach the solution of David Veeneman provided in this answer might be helpful:
Entity Framework 4 and WPF
It's not a full WPF example but can serve as a foundation how to extend an ObservableCollection in a way that it supports Create-Update-Delete operations with Entity Framework.
Related
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!
I need geometry types in my Entity Framework application. I've tried to follow this tutorial but I have had some issues and I'm not sure if it is because the tutorial is old or if I'm doing something wrong.
For example, under "Creating a New Entity C# Code Generation Template" it says
select Entity C# in the "Load from existing template" drop-down list.
The closest thing I can find, how ever, is the "EntityObject" template. Also, the code in the EntityObject template is somewhat different and so I don't know if this will still work.
Also, the link to the template code is down so you have to transcribe the entire picture of code, which is inconvenient (especially if it turns out not to work).
My question is, is there a better/updated way to handle spatial datatypes with entity framework and postgresql in the year of 2013?
Thanks
Support for spatial/geometry data types in Entity Framework 5 and Entity Framework 6 will be available in the next build of dotConnect for PostgreSQL. We plan to release the nearest build in a week or two.
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
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.
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.