This is a migrated thread and some comments may be shown as answers.

How to properly generate entity with FKs from DB

1 Answer 58 Views
Data Access Free Edition
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Kate
Top achievements
Rank 1
Kate asked on 30 Dec 2013, 02:11 PM
Im using Telerik OpenAcces Domian Model and Service with Silverlight 5 and MySQL Database

Its generated code by Model which i used:


-- web_aplikacja.Web.EwidencjonowanaRzecz
CREATE TABLE `EwidencjonowanaRzecz` (
    `WagaRef_id` integer NULL,              -- _waga
    `UserRef_id` integer NULL,              -- _user
    `Status` integer NULL,                  -- _status
    `RozmiarRef_id` integer NULL,           -- _rozmiary
    `OpisStanuPrzedmiotu` varchar(255) NULL, -- _opisStanuPrzedmiotu
    `Nazwa` varchar(255) NULL,              -- _nazwa
    `Model` varchar(255) NULL,              -- _model
    `Marka` varchar(255) NULL,              -- _marka
    `KtoZnalazl` varchar(255) NULL,         -- _ktoZnalazl
    `KolorRef_id` integer NULL,             -- _kolor
    `KategoriaRef_id` integer NULL,         -- _kategorium
    `Id` integer AUTO_INCREMENT NOT NULL,   -- _id
    `GdzieZnaleziono` varchar(255) NULL,    -- _gdzieZnaleziono
    `Data` datetime NULL,                   -- _data
    `CechySzczegolnePrzedmiotu` varchar(255) NULL, -- _cechySzczegolnePrzedmiotu
    CONSTRAINT `pk_EwidencjonowanaRzecz` PRIMARY KEY (`Id`)
) ENGINE = InnoDB;

-- web_aplikacja.Web.Kategorium
CREATE TABLE `Kategoria` (
    `Nazwa` varchar(255) NULL,              -- _nazwa
    `Id` integer AUTO_INCREMENT NOT NULL,   -- _id
    CONSTRAINT `pk_Kategoria` PRIMARY KEY (`Id`)
) ENGINE = InnoDB;

-- web_aplikacja.Web.Kolor
CREATE TABLE `Kolor` (
    `Id` integer AUTO_INCREMENT NOT NULL,   -- _id
    `Barwa` varchar(255) NULL,              -- _barwa
    CONSTRAINT `pk_Kolor` PRIMARY KEY (`Id`)
) ENGINE = InnoDB;

-- web_aplikacja.Web.Rozmiary
CREATE TABLE `Rozmiary` (
    `RozmiarZ` integer NULL,                -- _rozmiarZ
    `RozmiarY` integer NULL,                -- _rozmiarY
    `RozmiarX` integer NULL,                -- _rozmiarX
    `Id` integer AUTO_INCREMENT NOT NULL,   -- _id
    CONSTRAINT `pk_Rozmiary` PRIMARY KEY (`Id`)
) ENGINE = InnoDB;

-- web_aplikacja.Web.User
CREATE TABLE `User` (
    `Password` varchar(255) NULL,           -- _password
    `Login` varchar(255) NULL,              -- _login
    `InformacjeDodatkowe` varchar(255) NULL, -- _informacjeDodatkowe
    `Id` integer AUTO_INCREMENT NOT NULL,   -- _id
    `AdresBiuraRzeczyZnalezionych` varchar(255) NULL, -- _adresBiuraRzeczyZnalezionych
    CONSTRAINT `pk_usr` PRIMARY KEY (`Id`)
) ENGINE = InnoDB;

-- web_aplikacja.Web.Waga
CREATE TABLE `Waga` (
    `WagaPrzedmiotu` varchar(255) NULL,     -- _wagaPrzedmiotu
    `Id` integer AUTO_INCREMENT NOT NULL,   -- _id
    CONSTRAINT `pk_Waga` PRIMARY KEY (`Id`)
) ENGINE = InnoDB;

ALTER TABLE `EwidencjonowanaRzecz` ADD INDEX `WagaRef_id`(`WagaRef_id`);

ALTER TABLE `EwidencjonowanaRzecz` ADD INDEX `UserRef_id`(`UserRef_id`);

ALTER TABLE `EwidencjonowanaRzecz` ADD INDEX `RozmiarRef_id`(`RozmiarRef_id`);

ALTER TABLE `EwidencjonowanaRzecz` ADD INDEX `KolorRef_id`(`KolorRef_id`);

ALTER TABLE `EwidencjonowanaRzecz` ADD INDEX `KategoriaRef_id`(`KategoriaRef_id`);

ALTER TABLE `EwidencjonowanaRzecz` ADD CONSTRAINT `ref_EwidencjonowanaRzecz_Kategoria` FOREIGN KEY `ref_EwidencjonowanaRzecz_Kategoria` (`KategoriaRef_id`) REFERENCES `Kategoria` (`Id`);

ALTER TABLE `EwidencjonowanaRzecz` ADD CONSTRAINT `ref_EwidencjonowanaRzecz_Kolor` FOREIGN KEY `ref_EwidencjonowanaRzecz_Kolor` (`KolorRef_id`) REFERENCES `Kolor` (`Id`);

ALTER TABLE `EwidencjonowanaRzecz` ADD CONSTRAINT `ref_EwidencjonowanaRzecz_Rozmiary` FOREIGN KEY `ref_EwidencjonowanaRzecz_Rozmiary` (`RozmiarRef_id`) REFERENCES `Rozmiary` (`Id`);

ALTER TABLE `EwidencjonowanaRzecz` ADD CONSTRAINT `ref_EwidencjonowanaRzecz_User` FOREIGN KEY `ref_EwidencjonowanaRzecz_User` (`UserRef_id`) REFERENCES `User` (`Id`);

ALTER TABLE `EwidencjonowanaRzecz` ADD CONSTRAINT `ref_EwidencjonowanaRzecz_Waga` FOREIGN KEY `ref_EwidencjonowanaRzecz_Waga` (`WagaRef_id`) REFERENCES `Waga` (`Id`);





XAML:

        <controls:RadGridView
BorderBrush="#FFAC9D9D"
GroupPanelForeground="Black"
GroupPanelBackground="#FFAC9D9D"
AlternateRowBackground="Blue"
Grid.Row="0"
x:Name="TableRadGridView"
ItemsSource="{Binding EwidencjaList}" 
d:DataContext="{d:DesignData}"
AutoGenerateColumns="False"
ColumnWidth="auto"
IsReadOnly="true"
FilteringMode="Popup" 
Width="auto" Height="auto"
FontSize="14"
BorderThickness="0" Foreground="Black" Background="{x:Null}" FontFamily="Comic Sans MS">

            <controls:RadGridView.Columns>
                <controls:GridViewDataColumn DataMemberBinding="{Binding Nazwa}" Header="Nazwa" Background="#FFAC9D9D" />
                <controls:GridViewDataColumn DataMemberBinding="{Binding UserRef_id}" Background="#FFAC9D9D" Header="Id"/>
                <controls:GridViewDataColumn DataMemberBinding="{Binding UserRef_id.AdresBiuraRzeczyZnalezionych}" Background="#FFAC9D9D" Header="Testowe"/>
            </controls:RadGridView.Columns>
        </controls:RadGridView>



And downloading data from service:

           baza = new ModelBazyUslugi();

            Task.Factory.StartNew(() =>
            {
                    LoadOperation<EwidencjonowanaRzecz> daneZBazy =
                    baza.Load(baza.GetEwidencjonowanaRzeczsQuery());
                    daneZBazy.Completed += (s, args) =>
                    {
                        EwidencjaList = new ObservableCollection<EwidencjonowanaRzecz>(daneZBazy.Entities.ToList().Where(m => m.Status == 0));
                    }; 
                
            });


http://zapodaj.net/207b90b2f2238.png.html
I want to get data User.AdresBiuraRzeczyZnalezionych from EwidencjonowanaRzecz, and show in RadGridView ( look at xaml file ) 

1 Answer, 1 is accepted

Sort by
0
Kristian Nikolov
Telerik team
answered on 01 Jan 2014, 04:28 PM
Hello Kate,

If I am understanding correctly you are using a RIA service.

If that indeed is the case, in order to access Navigation Properties, you will have to add AssociationAttribute to the required property of the respective  service proxy class. Since the proxy classes are auto-generated, you will have to use buddy classes to extend them. This documentation article details the process of handling relationships in RIA services.

I hope this helps.

Regards,
Kristian Nikolov
Telerik
OpenAccess ORM Q3 2013 simplifies your model operations even further providing you with greater flexibility. Check out the list of new features shipped with our latest release!
Tags
Data Access Free Edition
Asked by
Kate
Top achievements
Rank 1
Answers by
Kristian Nikolov
Telerik team
Share this question
or