Entity Framework 6 - finally, success with an Entity 'mapping'
Posted: Wed Dec 14, 2016 10:05 am
Hi Robert, Team, and guys,
Well, I thought you may wish to know that yesterday I got my first X# successful mapping of an Entity, albeit a simple one.
I have a simple 'Supplier' class with properties of just value type. I then have a second class called 'Product' which has mainly value type properties but also one other, a 'virtual' property which is itself of business class type 'Supplier'.
The following image shows the seed data bound to two data grid controls :-
In the top data grid you can see the Supplier object as the ToString() method involves three of its value type properties.
Now the good thing about Entity mapping is that the LINQ code is still simple - no need for JOINs which many 'fear', or hate (Nick!).
Here is the code to retrieve the Product data (Image '_32' ) :-
Here below is the simple WPF data binding :-
Of course if the query using LINQ is simple then the complexity has to be in the mapping and also for me in how I seed the test data. Below is some code for table population - note that the Supplier table data needs to be seeded (and in place in the SQL database) before this Product seed code is run :- image '_35'
If we seed and populate in the wrong order we can get this - see below :- (image '_36')
*** Note 36,37,38 images in next post - too many links !!! Robert ? ***
... image 36 ...
Reversing these lines of code get us success once again :- (image '_37' )
image '_37'
Now you may like to see just what a simple change I had to make to the Product class definition to bring all this about - get stuff to happen. Well below we need to view line 276, that's all, and see that the other properties are on lines 254-256. Most of the rest of the class definition has been collapsed so we can see clearly what is going on, even if it is not much ;-0)
image '_38 (next post)
So for those people who understand English and British humour we could say that "nobody can see the join ! "
Regards,
Phil.
P.S. I will now go and add more classes like 'Order' and 'OrderLine', 'Customer' and 'Invoice', and make Entity mappings right from their inclusion (from the start).
Oh! and by the way, I am managing in VS without any Intellisense, but it would be nice to have what Frabrice is working on for us ;-0)
Well, I thought you may wish to know that yesterday I got my first X# successful mapping of an Entity, albeit a simple one.
I have a simple 'Supplier' class with properties of just value type. I then have a second class called 'Product' which has mainly value type properties but also one other, a 'virtual' property which is itself of business class type 'Supplier'.
The following image shows the seed data bound to two data grid controls :-
In the top data grid you can see the Supplier object as the ToString() method involves three of its value type properties.
Now the good thing about Entity mapping is that the LINQ code is still simple - no need for JOINs which many 'fear', or hate (Nick!).
Here is the code to retrieve the Product data (Image '_32' ) :-
Here below is the simple WPF data binding :-
Of course if the query using LINQ is simple then the complexity has to be in the mapping and also for me in how I seed the test data. Below is some code for table population - note that the Supplier table data needs to be seeded (and in place in the SQL database) before this Product seed code is run :- image '_35'
If we seed and populate in the wrong order we can get this - see below :- (image '_36')
*** Note 36,37,38 images in next post - too many links !!! Robert ? ***
... image 36 ...
Reversing these lines of code get us success once again :- (image '_37' )
image '_37'
Now you may like to see just what a simple change I had to make to the Product class definition to bring all this about - get stuff to happen. Well below we need to view line 276, that's all, and see that the other properties are on lines 254-256. Most of the rest of the class definition has been collapsed so we can see clearly what is going on, even if it is not much ;-0)
image '_38 (next post)
So for those people who understand English and British humour we could say that "nobody can see the join ! "
Regards,
Phil.
P.S. I will now go and add more classes like 'Order' and 'OrderLine', 'Customer' and 'Invoice', and make Entity mappings right from their inclusion (from the start).
Oh! and by the way, I am managing in VS without any Intellisense, but it would be nice to have what Frabrice is working on for us ;-0)