xsharp.eu • This Entity stuff just works ! Great with LINQ ...
Page 1 of 1

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

Posted: Thu Jan 19, 2017 12:43 pm
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 474 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 474 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 474 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 474 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 474 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 474 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 474 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 474 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 474 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.

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

Posted: Thu Jan 19, 2017 1:25 pm
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.

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

Posted: Thu Jan 19, 2017 3:53 pm
by FFF
Works - albeit i miss some sound ;)

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

Posted: Fri Jan 20, 2017 12:53 pm
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.

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

Posted: Fri Jan 20, 2017 12:58 pm
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 ;->

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

Posted: Fri Jan 20, 2017 1:43 pm
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

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

Posted: Fri Jan 20, 2017 5:04 pm
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.