Entity Framework 6 - first steps to a full xBase solution

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

Entity Framework 6 - first steps to a full xBase solution

Post by Phil Hepburn »

Robert,

I think I tried various combinations of syntax yesterday - and here I have tried your suggestion - gives the same result so I will now work on the small sample I promised yesterday.

Looks like I need some extra help to get my C# working syntax in-line with Nick's greater experience ;-)

Still, if it is working C# then we ought to be able to translate it.

Actually, I got the Lambda syntax from the Reflector translation of Fabrice's plug-in and my C# code.

Maybe we should start to just manually translate the C# I showed earlier.

Cheers,
Phil.
EF_XS_21.jpg
EF_XS_21.jpg (36.13 KiB) Viewed 636 times
User avatar
Phil Hepburn
Posts: 743
Joined: Sun Sep 11, 2016 2:16 pm

Entity Framework 6 - first steps to a full xBase solution

Post by Phil Hepburn »

Nick,

Thanks for joining in and bringing your greater experience with EF6 and writing configurations.

I got the original C# code for my Configurations working a few years back and have not really re-visited it except for adding sections similar to what is in existence in other classes. Maybe I need a re-think to make the C~ code 'smarter' and in-line with what you do.

Can you send me a full example of one or more of your configuration classes, and include those which show a wide variety of what was Attributes ?

If you rather work personally and direct, then do so, then I can post what we get working, and which is tidier and smoother on the eye.

Thanks a bundle,
Phil.

P.S. Attached is the most complex of my Cologne 2015 examples.
EF_XS_22.jpg
EF_XS_22.jpg (46.11 KiB) Viewed 636 times
User avatar
robert
Posts: 4529
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Entity Framework 6 - first steps to a full xBase solution

Post by robert »

Phil,

AFAIK the expression syntax works. Look at the example below:

Code: Select all

USING System.Linq.Expressions
FUNCTION Start AS VOID
	VAR  oExp := (Expression<@@Func<STRING,STRING>>) {|c|c:ToUpper()} 
	? oExp
	VAR oDel := oExp:Compile()
	? oDel
	? oDel("phil")
	RETURN
Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
User avatar
Phil Hepburn
Posts: 743
Joined: Sun Sep 11, 2016 2:16 pm

Entity Framework 6 - first steps to a full xBase solution

Post by Phil Hepburn »

Robert,

I have dropped the '.Lambda' and tried what you sent me.

Since I still have the attached image error, I think it best if I continue to work with Nick to get me a clear and clean (and suitable) C# working version on which to then work to convert to X#.

He may shine a light where I am fumbling in the dark !

Thanks for helping, I will be in touch later.

Cheers,
Phil.
EF_XS_31.jpg
EF_XS_31.jpg (31.41 KiB) Viewed 636 times
User avatar
robert
Posts: 4529
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Entity Framework 6 - first steps to a full xBase solution

Post by robert »

Phil,

Did you try:

Code: Select all

super:@@Property({|e|e:ProductCode}):IsRequired()
The expression:

Code: Select all

{|e|e:ProductCode}
IS a lambda expression

This should be equivalent to the C# code

Code: Select all

base.Property( e=>e.ProductCode).IsRequired()
Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
User avatar
Phil Hepburn
Posts: 743
Joined: Sun Sep 11, 2016 2:16 pm

Entity Framework 6 - first steps to a full xBase solution

Post by Phil Hepburn »

Okay Robert,

Done that and we seem now to get compilation OK - no DB yet however.

Attached are two ways of coding / syntax - one using 'Super' and one using 'Self', they both compile.

I found some C# stuff this morning that used 'This' and not 'Base'.

What would you recommend I use for X# ?

Am still working with Nick to improve my original code - BUT - I am not as yet creating a database in SQL. No errors as such.

But we can worry about that a bit later ;-0)

Speak soon,
Phil.

P.S. keep sending any ideas that come to your mind.
Oh! and the yellow light bulb in VS2015 has helped me clean my original C# code, and it still works as in Cologne. See images.
EF_XS_41.jpg
EF_XS_41.jpg (84.49 KiB) Viewed 636 times
NF_Config_11.jpg
NF_Config_11.jpg (39.78 KiB) Viewed 636 times
NF_Config_12.jpg
NF_Config_12.jpg (76.3 KiB) Viewed 636 times
User avatar
Phil Hepburn
Posts: 743
Joined: Sun Sep 11, 2016 2:16 pm

Entity Framework 6 - first steps to a full xBase solution

Post by Phil Hepburn »

Whoops !

Here is the 'super' to go with the earlier 'self' :-

Phil.
EF_XS_42.jpg
EF_XS_42.jpg (86.63 KiB) Viewed 636 times
User avatar
robert
Posts: 4529
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Entity Framework 6 - first steps to a full xBase solution

Post by robert »

Phil,

I am glad this is resolved now, and also without the ugly casts etc and by using the simple codeblock style Lambda Expression.

W.r.t. the difference between base and this (SUPER and SELF):

I do not think there is much difference here, unless you are going to overwrite the ToTable() or Property() method in your code. It is a matter of personal preference:

You could argue for base/SUPER, beause this documents that the method is implemented in the parent class

You could also argue for this/SELF, because that would ensure that an overwrite of these methods will automatically be called on places where you use it.

In the end it is just personal preference I think.

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

Entity Framework 6 - first steps to a full xBase solution

Post by Phil Hepburn »

Hi Robert - THANKS,

You and Nick have got me SUCCESS - first DB created from a total X# EF6 applet.

Okay I did a bit of slog work myself, but you and Nick provided the extra knowledge and a good dollop of inspiration as well.

Good team work I think.

Now that I have a runner - albeit rather simple, I can flesh this out to be a few proper entities - and just a bit more fun and games as well ;-0)

I attach a couple of success type images for information to our X# colleagues :-

Best regards to one and all - AND - I have earned myself a nice piece of Julie's cake ;-0)
Phil.
EF_XS_52.jpg
EF_XS_52.jpg (94.15 KiB) Viewed 636 times

EF_XS_51.jpg
EF_XS_51.jpg (179.04 KiB) Viewed 636 times
User avatar
Phil Hepburn
Posts: 743
Joined: Sun Sep 11, 2016 2:16 pm

Entity Framework 6 - first steps to a full xBase solution

Post by Phil Hepburn »

Okay you guys, we are on our way ..........

Now we have some simple 'seeding' and data 'Population'.

Checkout these easy images for adding Product data rows to the new Table.

The database engine provides the values for the ID's.
EF_XS_62.jpg
EF_XS_62.jpg (151.13 KiB) Viewed 636 times
EF_XS_64.jpg
EF_XS_64.jpg (53.11 KiB) Viewed 636 times
EF_XS_63.jpg
EF_XS_63.jpg (25.78 KiB) Viewed 636 times
EF_XS_65.jpg
EF_XS_65.jpg (45.44 KiB) Viewed 636 times
EF_XS_61.jpg
EF_XS_61.jpg (48.42 KiB) Viewed 636 times
Out of interest I have not apparently 'forced' the primary key, it has been done by the compiler and DB engine with what limited code I provided.

Some stuff seems to be being done for us by the EF framework and related 'behind the scenes'.

Hope this X# success interests a few of you guys. And note that the earlier code and syntax 'struggles' have come down eventually to some really very simple code - which works ;-0)

Cheers,
Phil.
Post Reply