fbpx
Welcome, Guest
Username: Password: Remember me
Share your code snippets, screen shots etc. here
  • Page:
  • 1

TOPIC: Entity Framework 6 - first steps to a full xBase solution

Entity Framework 6 - first steps to a full xBase solution 2 years 3 months ago #1

  • Phil Hepburn
  • Phil Hepburn's Avatar Topic Author
  • Offline
  • Posts: 737
  • Karma: 7
Hi Robert, Team, and guys,

Well, I now have my head back into 'Entity Framework 6' (as version 7 seems a long way off, and will most likely be 'Entity Core' instead, according to wen articles etc..

Still 'EF6' is working well in C#, and is set to be around for quite some time according to reliable sources.

So I am first trying to convert my old Vulcan / C# 'hybrid' Cologne apps into fully coded X# ones. In the past I used a 'thin' DAL (data access layer) where the LINQ stuff was done in C# and the other stuff in Vulcan. Nice WPF data bound example.

I have some of code compiling with the X# compiler, but now I am having some problems with the 'Configuration' classes, when I try and code them in X# from CSharp. And Fabrice's Reflector plug-in gives me an amazing complex and large translation ;-0( It may be correct BUT will put guys off EF for life I would guess ;-0)

Can you just look at the first three attached small images to see if you can see what I can do (easily) to put things right ?

Here is the CSharp code :-



And now you can see what I was trying :-



Here below (included) is an image of my best try as well as the errors :-



And for any who wish to see the Reflector details ;-0))) see below (if you can read the detail !?



HELP most welcomed.

Regards,
Phil.
Attachments:

Please Log in or Create an account to join the conversation.

Entity Framework 6 - first steps to a full xBase solution 2 years 3 months ago #2

  • wriedmann
  • wriedmann's Avatar
  • Away
  • Posts: 1436
  • Karma: 6
Hi Phil,

maybe a first help: "func" is a reserved word in X#.

The following code fails to compile:
class Func
end class

where as
class @@Func
end class

compiles.

Maybe you could try to write <func> as <@@func>

Wolfgang

P.S. this code compiles on my machine:
using System.Collections.Generic

class @@func
end class

class TestFunc    
	protect oFuncs		as List<@@Func>
end class
Wolfgang Riedmann
Meran, South Tyrol, Italy
This email address is being protected from spambots. You need JavaScript enabled to view it.
www.riedmann.it - docs.xsharp.it

Please Log in or Create an account to join the conversation.

Last edit: by wriedmann.

Entity Framework 6 - first steps to a full xBase solution 2 years 3 months ago #3

  • Phil Hepburn
  • Phil Hepburn's Avatar Topic Author
  • Offline
  • Posts: 737
  • Karma: 7
Thanks Wolfgang,

Great!

That has gotten me further it would seem - so now I have the following single issue being reported.

Any ideas - you or anyone else ?

Thanks in advance ;-0)
Phil.

Attachments:

Please Log in or Create an account to join the conversation.

Entity Framework 6 - first steps to a full xBase solution 2 years 3 months ago #4

  • Phil Hepburn
  • Phil Hepburn's Avatar Topic Author
  • Offline
  • Posts: 737
  • Karma: 7
Sorry,

Wrong image - must be watching the football has made my concentration go ;-0)

Try two

Please Log in or Create an account to join the conversation.

Entity Framework 6 - first steps to a full xBase solution 2 years 3 months ago #5

  • Phil Hepburn
  • Phil Hepburn's Avatar Topic Author
  • Offline
  • Posts: 737
  • Karma: 7
Try three ?



This should be a single error line reported .............>>

Cheers,
Phil.
Attachments:

Please Log in or Create an account to join the conversation.

Entity Framework 6 - first steps to a full xBase solution 2 years 3 months ago #6

  • wriedmann
  • wriedmann's Avatar
  • Away
  • Posts: 1436
  • Karma: 6
Hi Phil,

this try was the right one <g>. But I have let this to someone other, maybe Chris or Robert.

Wolfgang

P.S. have to go back to VO programming now
Wolfgang Riedmann
Meran, South Tyrol, Italy
This email address is being protected from spambots. You need JavaScript enabled to view it.
www.riedmann.it - docs.xsharp.it

Please Log in or Create an account to join the conversation.

Entity Framework 6 - first steps to a full xBase solution 2 years 3 months ago #7

Phil
Can you create a small (10 line) sample without external depedencies that reproduces this ?

Robert
XSharp Development Team
The Netherlands
This email address is being protected from spambots. You need JavaScript enabled to view it.

Please Log in or Create an account to join the conversation.

Entity Framework 6 - first steps to a full xBase solution 2 years 3 months ago #8

  • Phil Hepburn
  • Phil Hepburn's Avatar Topic Author
  • Offline
  • Posts: 737
  • Karma: 7
Hi Robert,

Yes, I think I can do that tomorrow - too late tonight, and I have spent enough brain power on EF6 for today ;-0)

Although I can make a small example - without outside dependencies - just 10 lines may be pushing things a bit.

Fingers crossed I can send you something useful. I have got quite a way with this in order to get EF6 working, this just feels like the last step (or two) - then we will 'have it'.

Do you wish me to send the code etc., to your private mail box ? It would seem like the best thing to do. I can then post stuff when we get a working syntax, and the code nice and tidy.

All the best,
Phil.

Please Log in or Create an account to join the conversation.

Entity Framework 6 - first steps to a full xBase solution 2 years 3 months ago #9

Phil,

If I look at your example (on a larger screen then yesterday) I see:

System:Linq:Expressions:Expression:Lambda<.....>

Shouldn't that be:

System.Linq.Expressions.Expression.Lambda<.....>

Not sure if this solves your problem, but I think these are all namespace delimiters and should be dots in stead of colons.

Robert
XSharp Development Team
The Netherlands
This email address is being protected from spambots. You need JavaScript enabled to view it.

Please Log in or Create an account to join the conversation.

Entity Framework 6 - first steps to a full xBase solution 2 years 3 months ago #10

Hi Phil,

I may be missing something, but I don't understand your original C#. Why not just use something like
HasOptional(e => e.Attendee).WithMany().HasForeignKey(x => x.AttendeeID)
That ought to translate to X#.
Or just use Nullable<>.

Nick

Please Log in or Create an account to join the conversation.

Last edit: by NickFriend.

Entity Framework 6 - first steps to a full xBase solution 2 years 3 months ago #11

  • Phil Hepburn
  • Phil Hepburn's Avatar Topic Author
  • Offline
  • Posts: 737
  • Karma: 7
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.

Attachments:

Please Log in or Create an account to join the conversation.

Entity Framework 6 - first steps to a full xBase solution 2 years 3 months ago #12

  • Phil Hepburn
  • Phil Hepburn's Avatar Topic Author
  • Offline
  • Posts: 737
  • Karma: 7
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.

Attachments:

Please Log in or Create an account to join the conversation.

Entity Framework 6 - first steps to a full xBase solution 2 years 3 months ago #13

Phil,

AFAIK the expression syntax works. Look at the example below:
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
This email address is being protected from spambots. You need JavaScript enabled to view it.

Please Log in or Create an account to join the conversation.

Entity Framework 6 - first steps to a full xBase solution 2 years 3 months ago #14

  • Phil Hepburn
  • Phil Hepburn's Avatar Topic Author
  • Offline
  • Posts: 737
  • Karma: 7
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.

Attachments:

Please Log in or Create an account to join the conversation.

Entity Framework 6 - first steps to a full xBase solution 2 years 3 months ago #15

Phil,

Did you try:
super:@@Property({|e|e:ProductCode}):IsRequired()

The expression:
{|e|e:ProductCode}

IS a lambda expression

This should be equivalent to the C# code
base.Property( e=>e.ProductCode).IsRequired()

Robert
XSharp Development Team
The Netherlands
This email address is being protected from spambots. You need JavaScript enabled to view it.

Please Log in or Create an account to join the conversation.

Entity Framework 6 - first steps to a full xBase solution 2 years 3 months ago #16

  • Phil Hepburn
  • Phil Hepburn's Avatar Topic Author
  • Offline
  • Posts: 737
  • Karma: 7
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.





Attachments:

Please Log in or Create an account to join the conversation.

Entity Framework 6 - first steps to a full xBase solution 2 years 3 months ago #17

  • Phil Hepburn
  • Phil Hepburn's Avatar Topic Author
  • Offline
  • Posts: 737
  • Karma: 7
Whoops !

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

Phil.

Attachments:

Please Log in or Create an account to join the conversation.

Entity Framework 6 - first steps to a full xBase solution 2 years 3 months ago #18

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
This email address is being protected from spambots. You need JavaScript enabled to view it.

Please Log in or Create an account to join the conversation.

Entity Framework 6 - first steps to a full xBase solution 2 years 3 months ago #19

  • Phil Hepburn
  • Phil Hepburn's Avatar Topic Author
  • Offline
  • Posts: 737
  • Karma: 7
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.



Attachments:

Please Log in or Create an account to join the conversation.

Entity Framework 6 - first steps to a full xBase solution 2 years 3 months ago #20

  • Phil Hepburn
  • Phil Hepburn's Avatar Topic Author
  • Offline
  • Posts: 737
  • Karma: 7
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.











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.

Please Log in or Create an account to join the conversation.

  • Page:
  • 1