Hello NewsGroup,

I have created a little example with the Join Operator. But I'm a
newbie in LinQ, so I dont know if its my fault.
I have two tables: hotel and guest. In guest is a foreign key to
hotel. Now I want to make a Join in VB:
> Dim HotelJoin = From Hotel In oDb.Hotel Join Guest In oDb.Guest On Hotel.ID 
> Equals Guest.HotelID

But it does not work. The HotelJoin.First() function throws an
exception 1010. Does somebody know what I'm doing wrong?


Regards

Mike
PS: I have attached a SQL Script for creating the database and the VB
Function for verifying the error.


########################################################################################
#### This SQL script creates one database (tourist) and two tables
(hotel and guest) in a MySQL DB:
CREATE SCHEMA IF NOT EXISTS `Tourist` DEFAULT CHARACTER SET latin1
COLLATE latin1_german1_ci ;
USE `Tourist`;

-- -----------------------------------------------------
-- Table `Tourist`.`Hotel`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `Tourist`.`Hotel` ;

CREATE  TABLE IF NOT EXISTS `Tourist`.`Hotel` (
  `ID` INT UNSIGNED NOT NULL AUTO_INCREMENT ,
  `HotelName` VARCHAR(45) NOT NULL ,
  PRIMARY KEY (`ID`) )
ENGINE = InnoDB
COMMENT = '<double-click to overwrite multiple objects>';


-- -----------------------------------------------------
-- Table `Tourist`.`Guest`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `Tourist`.`Guest` ;

CREATE  TABLE IF NOT EXISTS `Tourist`.`Guest` (
  `ID` INT UNSIGNED NOT NULL AUTO_INCREMENT ,
  `GuestName` VARCHAR(50) NULL ,
  `Hotel_ID` INT UNSIGNED NOT NULL ,
  PRIMARY KEY (`ID`) ,
  INDEX `fk_Gast_Hotel` (`Hotel_ID` ASC) ,
  CONSTRAINT `fk_Gast_Hotel`
    FOREIGN KEY (`Hotel_ID` )
    REFERENCES `Tourist`.`Hotel` (`ID` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB
########################################################################################

########################################################################################
#### Try this function to test the join:
Sub Main()

    Dim sBogenDbConnInfo As String = "server=127.0.0.1;user id=root;
password=root; database=Tourist"
    Dim oDb As TouristLinq.Tourist = New TouristLinq.Tourist(New
MySql.Data.MySqlClient.MySqlConnection(sBogenDbConnInfo))

    Dim HotelJoin = From Hotel In oDb.Hotel _
        Join Guest In oDb.Guest _
            On Hotel.ID Equals Guest.HotelID
    ' HotelJoin is empty? But I have inserted matching entries in
table hotel and guest?
    Dim Row1 = HotelJoin.First() ' Here I get the exception 1010

    Dim o = From HotelList In oDb.Hotel ' Here I get my one and only
hotel row
    Dim p = From GuestList In oDb.Guest ' In p is the Guest saved. All
ID's are 1, so the values fit.

End Sub
########################################################################################
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"DbLinq" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/dblinq?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to