This Entity stuff just works ! Great with LINQ ...

Public forum to share code snippets, screen shorts, experiences, etc.
Post Reply
User avatar
Phil Hepburn
Posts: 743
Joined: Sun Sep 11, 2016 2:16 pm

This Entity stuff just works ! Great with LINQ ...

Post by Phil Hepburn »

Hi guys,

Well, around my time making picture frames (recently) I have managed to move-forward the demo app for Cologne, on LINQ and Entity Framework, with WPF/XAML and data binding. The results of the development are even amazing to me - he who designed it !

Entity Framework 6 takes so much of the mundane 'boring' bits out of database work that it almost makes me smile.

First of all lets see the finished input screen for a user to create and save a new Order for a selected customer :-
Pearls_EF6_70.jpg
Pearls_EF6_70.jpg (113.52 KiB) Viewed 476 times
Note that all the screen data is 'data bound' as public properties in the ViewModel. The zero entries in the cells of the DataGrid show that the EF6 system has not yet saved the new order, as it will eventually allocate IDs when it does.

We have made the code as clean as it should be for an MVVM approach, and the code behind looks like this :-
Pearls_EF6_76.jpg
Pearls_EF6_76.jpg (29.01 KiB) Viewed 476 times
For anyone who has had to use ADO.NET in the past years, and do all the database work the hard way in code, they/you will not believe how little needs to be done to save a business entity (like the customer's order) - check this out :-
Pearls_EF6_71.jpg
Pearls_EF6_71.jpg (32.64 KiB) Viewed 476 times
All we need do is use the objects of the bound public properties to add a new order into the selected customer's order list - no need to worry about identities and how they are saved, we just need to deal with IDs that already exist.

Oh! we also need to see how simple it is to launch the ViewModel / View pair in the first place :-
Pearls_EF6_77.jpg
Pearls_EF6_77.jpg (67.61 KiB) Viewed 476 times
Yes, we do need to have a bunch of public properties within our ViewModel for data binding, at is the secret to getting all this stuff to work so simply ;-0) Here are the private fields which match the PPs on a one to one basis :-
Pearls_EF6_78.jpg
Pearls_EF6_78.jpg (89.52 KiB) Viewed 476 times
Once we click the green 'save' button the new order data is sent to the back-end data SQL server and persisted - then as if by magic the EF and WPF system show the newly allocated IDs for order and order lines - see below :-
Pearls_EF6_72.jpg
Pearls_EF6_72.jpg (118.16 KiB) Viewed 476 times
Now we can use some of the other features to check-out what we have just done. The red button for Orders in the Entities group box shows this below :-
Pearls_EF6_74.jpg
Pearls_EF6_74.jpg (81.87 KiB) Viewed 476 times
And the OrderLines can bee seen with the cyan button, a click to launch a RelayCommand :-
Pearls_EF6_73.jpg
Pearls_EF6_73.jpg (83.64 KiB) Viewed 476 times
Finally we can look at the customer form and look into an appropriately nested combo box (drop list) - all this as we have to do little in code except get the Entity mapping correct in the first place - check below :-
Pearls_EF6_75.jpg
Pearls_EF6_75.jpg (177.74 KiB) Viewed 476 times
Enough of this magic for now, in another post I may show how easy it was to save each new order line.

Hope this interests a few of you guys.

Best Regards,
Phil.
Wales, UK.
User avatar
Phil Hepburn
Posts: 743
Joined: Sun Sep 11, 2016 2:16 pm

This Entity stuff just works ! Great with LINQ ...

Post by Phil Hepburn »

Hi guys,

I tried to attach a short video clip of me running the demo LINQ / Entity app - BUT - it can't be attached as it is an disallowed file format.

The video is here:

[The extension mp4 has been deactivated and can no longer be displayed.]

Please can yo try to acquire this and then run it ? Let me know of either success or failure.

Good Luck and fingers crossed,
Phil.
FFF
Posts: 1580
Joined: Fri Sep 25, 2015 4:52 pm
Location: Germany

This Entity stuff just works ! Great with LINQ ...

Post by FFF »

Works - albeit i miss some sound ;)
Regards
Karl
(on Win8.1/64, Xide32 2.20, X#2.20.0.3)
User avatar
Phil Hepburn
Posts: 743
Joined: Sun Sep 11, 2016 2:16 pm

This Entity stuff just works ! Great with LINQ ...

Post by Phil Hepburn »

Sorry Karl,

Office PC does not have a microphone, and I unfortunately don't speak German other than a few words and phrases ;-0)

Or is it the tip-tap and clitter-clatter of the keyboard that you miss ?

Regards, and thanks for testing,
Phil.

P.S. it surprised me how the link to the OneDrive file actually got the MP4 file to run as a video with just one click. Great this OneDrive technology.
FFF
Posts: 1580
Joined: Fri Sep 25, 2015 4:52 pm
Location: Germany

This Entity stuff just works ! Great with LINQ ...

Post by FFF »

dr philip h. hepburn wrote:...Or is it the tip-tap and clitter-clatter of the keyboard that you miss ?
Nope - but, as my son would say, some "stylish" background music is a must ;->
Regards
Karl
(on Win8.1/64, Xide32 2.20, X#2.20.0.3)
User avatar
robert
Posts: 4518
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

This Entity stuff just works ! Great with LINQ ...

Post by robert »

Phil,
dr philip h. hepburn wrote:Sorry Karl,

it surprised me how the link to the OneDrive file actually got the MP4 file to run as a video with just one click. Great this OneDrive technology.
No magic. I added the mp4 extension as an allowed extension, downloaded your MP4, acttached it to your message and inserted the document in the message.


Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
User avatar
Phil Hepburn
Posts: 743
Joined: Sun Sep 11, 2016 2:16 pm

This Entity stuff just works ! Great with LINQ ...

Post by Phil Hepburn »

Thanks Robert,

That is why (therefore) that is clicks and runs "like Magic! "

End result is great at this end.

Don't panic, I won't over-use it ;-0)

X# and VS 2017 working very well together here in Newport, UK.

Have a nice weekend, one and all.
Phil.
Post Reply