WPF Entity Framework CRUD operation review
-
2012年4月7日 下午 03:23
Hi,
I am developing small application to around WPF and EF for first time to gain better understanding on these technologies. Need your inputs if I am going in right direction or you guys have some other best practice suggestions.
Also note, application is simple with basic CRUD operations, so I am not planning to go for MVVM pattern.
Following are my concerns/queries:
1. Should i consider using 3 layers? DAL, BLL and UI layer?
2. Application has Customer, Product and Order entity where each Order has CustomerId, ProductId, quantity, etc. I need to display all of orders in Grid with Customer Name and Product Name. Should I consider writing new DTOOrders which will have CustomerName, ProductName, Quantity, TransactionDate etc, so that I can bind this DTO directly to grid. Is this right, or should I be using entities generated by EF and not creating new DTOs?
3. To serve Insert update delete, I will have to update the order DTO/entity collection and update DB through EntityFramework context object. However I am not sure how to go about using context object when I am using 3 layers viz DAL, BLL and UI
Looking forward on some guidance around my concerned area.
Regards,
Abhilash
所有回覆
-
2012年4月9日 上午 09:45版主
Hi Abhilash,
According to your description, I understand you want to create a WPF application with Entity Framework with CRUD operation.
For the first question, you can reference what Bob said in this link:http://social.msdn.microsoft.com/Forums/en/adodotnetentityframework/thread/7d63a30f-24f3-4343-b8ab-fe9df7d2e413
and for the second question, you don't need EF to create a DTOs, if you can bind DTO to Grid directly.
Here are some links about how to use Entity Framework in WPF for your reference:
http://msdn.microsoft.com/en-us/vstudio/Video/dd776537
http://msdn.microsoft.com/en-us/vstudio/bb466226
http://www.codeproject.com/Articles/34143/Two-Way-DataBinding-with-WPF-XBAP-and-the-ADO-NET
Hope it helps.
Annabella Luo[MSFT]
MSDN Community Support | Feedback to us
- 已提議為解答 Joba DinizMicrosoft Community Contributor 2012年4月9日 下午 06:03
-
2012年4月12日 下午 03:34
@Annabella,
Thanks for the sharing the information.
Regarding my second query, I guess you misunderstood what I meant. Once i create EDMX file, entities are generated. Is it recommended to have own custom DTOs apart from entities? If yes, I will have to populate DTOs from the data fetched in entity from DB. Or do you recommend me to directly access entities of EF across all layers viz BLL and UI ?
Also regarding my 3rd query, I am concerned more on using EF context object. Could you please clarify on this:
1. Entities are populated by fetching data from DB by creating new instance of Entity context object.
2. DTOs are passed to UI through DAL->BLL->UI
3. User updates UI, effectively updating DTOs (two way binding).
4. Pass DTOs back to DAL
5. Update enitities back to DB using context.savechanges()My concern is if i create new context object in step 1 and step 5, will call to SaveChanges save all inserted/updated DTO to DB when the Context object is newly create in Save function of DAL?
Regards,
Abhilash

