fbpx
Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC: Questions about X# definition

Questions about X# definition 2 years 1 month ago #1829

  beerhand's Avatar Topic Author beerhand Offline Posts: 23
X# Experts,

I have created this new topic to post several syntax questions related to the VS 17 and SQL use based on topic: https://www.xsharp.info/forum/public-chit-chat/288-moved-getting-going-with-sql-server-and-x-from-examplesChit-Chat: Getting going with SQL server and X# - from Examples:

I am still trying to understand the example Phil provided. Searching and reading the X# Help file was somewhat unsuccessful.

Q1: "Namespace" - it is used in each of the .Prg files. I assume it defines all prg's that belong to a soultion spread over muliple Progamm files? If I want to add a seperate prg-file I need to add the namespace in the file as well?

Q2: File DataContext.prg
"public class ForumDataContext inherit DataContext" -> where is DataContext defined. I have tried to search for it but could not find it. The X# Help file it was not mentioned. Is it part of .net and how can I the refernece for it?

Q3: Same file

public class ForumDataContext inherit DataContext
//
properties
public property ourCustomers as Table<Customer> auto -> could find any help for Table<xxx>


Q4: File TableDataClasses
[Table(Name := "dbo.Customer")]; -> see above, "table" is now in brackets no Table<xxx>

Q5 WPF-File
if file.Exists(cFilePath)... -> Function is clear. Is it a .net function? The X# help file only states "file() as boolean" not the "exists" method.

Thanks,
Michael

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

Questions about X# definition 2 years 1 month ago #1830

  wriedmann's Avatar wriedmann Offline Posts: 1567
Hi Michael,

Q1: "Namespace" - it is used in each of the .Prg files. I assume it defines all prg's that belong to a soultion spread over muliple Progamm files? If I want to add a seperate prg-file I need to add the namespace in the file as well?


an namespace is a possibility to group your code. If you have two different classes "Michael" in two different namespaces, they are different.

Normally you use one namespace per assembly, or even per assembly and folder.

Of course, you can work without namespaces or put all your code in the same namespace.

To uses classes from different namespaces, you can prefix them:
System.Data.Linq.DataContext{}

or use "using"
using System.Data.Linq

DataContext{}

Wolfgang
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.

Questions about X# definition 2 years 1 month ago #1831

  wriedmann's Avatar wriedmann Offline Posts: 1567
Hi Michael,

Q2: File DataContext.prg
"public class ForumDataContext inherit DataContext" -> where is DataContext defined. I have tried to search for it but could not find it. The X# Help file it was not mentioned. Is it part of .net and how can I the refernece for it?


Dr. Google is your best friend in this case:

https://msdn.microsoft.com/en-us/library/system.data.linq.datacontext(v=vs.110).aspx

Or you can use the brand new search facility:

https://docs.microsoft.com/dotnet/api

Currently, X# has no libraries, so all code you see in Phils samples come from the .NET framework (today I have read somewhere that the .NET Framework has about 14.500 classes).

To use the DataContext class, you need to add a reference to System.Data.Linq.dll to your application, and use a "using" statement or write the full path, including the namespace.

Wolfgang
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.

Questions about X# definition 2 years 1 month ago #1832

  wriedmann's Avatar wriedmann Offline Posts: 1567
Hi Michael,

Q3: Same file

public class ForumDataContext inherit DataContext
//
properties
public property ourCustomers as Table<Customer> auto -> could find any help for Table<xxx>

Again, the Table class is defined in System.Data.Linq (but there are other classes with the same name in other namespaces).

The expression Table<Customer> is a generic, and says that the Table contains elements of type "Customer". This gives the compiler the possibility to check the elements if they are the right type - imagine that as a type of string typed array.

Wolfgang
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.

Questions about X# definition 2 years 1 month ago #1833

  wriedmann's Avatar wriedmann Offline Posts: 1567
Hi Michael,

Q5 WPF-File
if file.Exists(cFilePath)... -> Function is clear. Is it a .net function? The X# help file only states "file() as boolean" not the "exists" method.


the .NET does not have any functions. "Exists" is a static method of the File class, i.e. a method that refers to the class and not to an specific instance of a class.
In X# functions are mapped to a hidden static class.

Again, this is a method and a class from the .NET framework:

https://docs.microsoft.com/en-us/dotnet/api/system.io.file

Wolfgang

P.S. I have left out Q4 for the moment, as I have to check it better and I'm a bit short of time
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.

Questions about X# definition 2 years 1 month ago #1835

  Phil Hepburn's Avatar Phil Hepburn Offline Posts: 742
Q4

This is part of the 'ORM' in L2S. [Object Relational Mapping.] It is a way to map the Table name in SQL to the .NET class, here called 'Customer' - I called them both the same name "Customer" but you don't have to.

Also the semi colon ( ; ) is to continue the attribute onto the next line. It is convention to do this and it makes the code more readable.

For a database in SQL to work with L2S and L2E we must have tables and columns mapped. Our .NET code does this for us.

HTH,
Phil.

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

Questions about X# definition 2 years 1 month ago #1851

  beerhand's Avatar Topic Author beerhand Offline Posts: 23
Thanks Wolfgang and Phil,

this was very helpful.

@Phil, please go ahead with the next steps.

Michael

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

Questions about X# definition 2 years 1 month ago #1854

  Phil Hepburn's Avatar Phil Hepburn Offline Posts: 742
Morning Michael,

Yes, I have been busy on the EF6 demo sample, even though I was silent yesterday.

For visual interest, and mental fun, below is an image of what I have in VS 2017 within my Virtual Machine :-



We are starting with no SQL database at all - that will be made by our .NET X# code when it is run.

The more complex set of classes will define a 'HouseHold' entity - which is built on a House (we call that a property - as in real estate), as well as a bunch of people, (Persons) who may have a bunch of vehicles. Obviously the house has a complex class property of address.

We as coders will keep our minds on only .NET code. We will define the five classes with there members, and also add some code to define a simple mapping between classes, properties and any table columns that the EF system feels right to create in Tables.

Watch this space ..........

Cheers,
Phil.
Wales, UK.
Attachments:

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

Questions about X# definition 2 years 1 month ago #1855

  Phil Hepburn's Avatar Phil Hepburn Offline Posts: 742
Hi Michael,

Oh! - just thought ...........

For the Entity Framework project, I think it a good idea if I start a new thread in Pearls, so do look out for it.

Cheers,
Phil.
Wales, UK.

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

Questions about X# definition 2 years 1 month ago #1867

  beerhand's Avatar Topic Author beerhand Offline Posts: 23
For today I have tried to rebuild Phil's example. Something is terrible going wrong.

Step 1: New X# Project
Step 2: Added Textblock and Datagrid in WPF
Step 3: Created new folder: DataContext
Step 3.1: Created DataContext.prg and used Phil's code
Step 3.2: Created TableDataClasses.prg and used Phil's code
Step 4: Created Connections.prg in folder Properties

If I compile i get the following error message(s) that are linked to missing references? Google was not a real help...Absolutely no clue what to do. :(

Error 1: XS0234 The type or namespace name 'SqlClients' does not exist in the namespace 'System.Data' (are you missing an assembly reference?) WpfApplication3

Error 2: XS0234 The type or namespace name 'Services' does not exist in the namespace 'System.Data' (are you missing an assembly reference?)

Error 3: XS0234 The type or namespace name 'Linq' does not exist in the namespace 'System.Data' (are you missing an assembly reference?)

There are a few more but I think lets fix these first maybe the others go away.

Thanks
Michael

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

Questions about X# definition 2 years 1 month ago #1869

  wriedmann's Avatar wriedmann Offline Posts: 1567
Hi Michael,

sorry, but I don't think that something is going terrible wrong.

In VO, you have to add libraries to your application, and in X#, you have to add assemblies to your references. In VO, most libraries were from the VO development team, and therefore documented inside the help. In X#, most libraries are from the .NET framework, and documented there.
As other "complication" in .NET you have the namespaces. It is not enough to add the assemblies (DLLs) to you application, but you need to declare also the namespaces with the "using" statement.

I can only point you again to the .NET API Browser:

https://docs.microsoft.com/de-de/dotnet/api/

It seems you have not included the right assembly to your project: System.Data.Linq is the library where most Linq functionality resides. Try to add this assembly and recompile.

Wolfgang

P.S. I were very confused in the beginning by all these terms.... And there are so many assemblies in the GAC (the global assembly cache)....
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.

Questions about X# definition 2 years 1 month ago #1870

  FFF's Avatar FFF Away Posts: 574
Wolfgang,
i suppose, Michael started using the WPF-App template, insofar i think he is justified in thinking, that all prerequisites are in place. But the template contains only references to System.Data and System.XML.Linq, but NOT to System.Data.Linq...

BTW, thx for the link, this is finally a seemingly quick reacting Ms site ;)

@Michael: for good help you have to provide better bug report <g>

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

Questions about X# definition 2 years 4 weeks ago #1899

  beerhand's Avatar Topic Author beerhand Offline Posts: 23
Hi Karl,

you are correct. I used the WPF-App template. Unfortunately I am still not able to reproduce Phil's examples (third try). I included all libraries/assemblies by hand into the code. Still getting the error messages as stated below. Next I have replaced the code with Phil's code. No success so far. I have checked and compared all settings (at least the obvious ones in the properties) but could not find any differences.

Maybe a question for Phil (when he is back): Did you use the WPF-App template?

Regards,
Michael

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

Questions about X# definition 2 years 4 weeks ago #1900

  wriedmann's Avatar wriedmann Offline Posts: 1567
Hi Michael,

maybe you should do a clean on your project, zip it up and attach it to your message, so someone of us could check and give you the solution.

Without seeing exactly the dependencies it is almost impossible to give you the right indications.

Wolfgang
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.

Questions about X# definition 2 years 4 weeks ago #1901

  beerhand's Avatar Topic Author beerhand Offline Posts: 23
Hi Wolfgang and others,

please find attached the project files.

Thanks,
Michael
Attachments:

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

Questions about X# definition 2 years 4 weeks ago #1902

  robert's Avatar robert Offline Posts: 994
Michael,

You seem to be trying to use Entity Framework, but you have no reference to Entity Framework in your project.

That is most likely why it fails.

You should be able to add a Nuget package for EntityFramework.

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.

Questions about X# definition 2 years 4 weeks ago #1903

  wriedmann's Avatar wriedmann Offline Posts: 1567
Hi Michael,

you have to add "System.Data.Linq" to your references.

Wolfgang
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.

Questions about X# definition 2 years 4 weeks ago #1904

  FFF's Avatar FFF Away Posts: 574
Wolfgang, Robert,
got me Michael's sln, installed, added Data.Ling & EF.
Still compile fails with (only):
..XS1061	'WPFWindow1' does not contain a definition for 'myDG_SelectionChanged' and no extension method 'myDG_SelectionChanged' accepting a first argument of type 'WPFWindow1' could 
be found (are you missing a using directive or an assembly reference?)...
Hopping around in the soluton expl. i opend packaces.config - from now on (not prior)
compile throughs an additional:
The google map can't be displayed, ask your administrator for more details

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

Last edit: by FFF. Reason: formatting

Questions about X# definition 2 years 4 weeks ago #1905

  wriedmann's Avatar wriedmann Offline Posts: 1567
Hi Karl,

I had the same error even without adding the Entity Framework - the code is not complete, maybe a typing error - and I have not the time to research all posts where the difference between Phils and Michaels code is. It would be enough that the declaration of this code is wrong, or that Phil has forgotten to show this method....

Wolfgang
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.

  • Page:
  • 1