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

Error after a persistent layer generation.

3 Answers 79 Views
Design Time (Visual Designer & Tools)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
ie
Top achievements
Rank 1
ie asked on 31 May 2010, 11:59 PM
Hey guys,

Should the ORM Wizard generate compilable model? I'm have the following structure:

CREATE TABLE Product 
    Id, -- PK  
    Name,  
    ... 
 
CREATE TABLE Shop 
    Id, -- PK  
    Name,  
    ... 
 
CREATE TABLE Product2Shop 
    ProductId, -- FK1 (Product.Id), PK 
    ShopId,    -- FK2 (Shop.Id),    PK 
 
CREATE TABLE ProductPriceHistory 
    Id,        -- PK 
    ProductId, -- FK (Product2Shop.ProductId) 
    ShopId,    -- FK (Product2Shop.ShopId) 
    Price, 
    PriceDate, 
    ...

I want to use FK to Product2Shop because of cascade delete. After the classes generation I'm having an error:

'DbLayer.ProductPriceHistory.Product2Shop' is a 'property' but is used like a 'type' DbLayer\ProductPriceHistory.Telerik.OpenAccess.cs

Is it a bug? Thanks.
  

3 Answers, 1 is accepted

Sort by
0
Ady
Telerik team
answered on 01 Jun 2010, 02:50 PM
Hi Ivan,

 I did create similar tables and reverse mapped them. The wizard treats the Product2Shop as a join table and creates a collection field in the 'Product' class. The 'ProductPriceHistory' table has a FK constraint to a join table and hence the wizard cannot correctly map a reference field for this FK constraint, in the 'ProductPriceHistory' class. We will fix this.
I am still not able to reproduce the error you mention. Can you provide your reversemapping.config file. This would help in reproducing the error soon.

Kind regards,
Ady
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
ie
Top achievements
Rank 1
answered on 01 Jun 2010, 11:34 PM
Hello Ady,

Please use the following SQL script to create the database, where I can reproduce the error:
CREATE TABLE Shop 
    Id    uniqueidentifier  NOT NULL  PRIMARY KEY
    Name  nvarchar(50)      NULL 
GO 
 
CREATE TABLE Product 
    Id    uniqueidentifier  NOT NULL  PRIMARY KEY
    Name  nvarchar(50)      NULL 
GO 
 
CREATE TABLE Product2Shop  
(  
    ProductId  uniqueidentifier  NOT NULL  REFERENCES Product(Id), 
    ShopId     uniqueidentifier  NOT NULL  REFERENCES Shop(Id), 
    CONSTRAINT PK_P2S PRIMARY KEY (ProductId, ShopId) 
)  
 
CREATE TABLE ProductPriceHistory  
(  
    Id         uniqueidentifier  NOT NULL  PRIMARY KEY
    ProductId  uniqueidentifier  NOT NULL
    ShopId     uniqueidentifier  NOT NULL
    Price      money             NOT NULL,  
    PriceDate  datetime2(7)      NOT NULL,  
    CONSTRAINT FK_P2S FOREIGN KEY (ProductId, ShopId) REFERENCES Product2Shop (ProductId, ShopId) 

I did nothing, just reverse mapped tables using wizard. As for my reversemapping.config file, it is exactly like this:

<?xml version="1.0" encoding="UTF-8"?> 
<openaccess> 
    <classGenerator defaultPackageName="ConsoleApplication2"
        <tables> 
            <table name="'Product'" type="1" locked="False"
                <column name="Id" isPk="True" isAutoInc="False" adoType="-11" sqlType="uniqueidentifier" length="0" isNull="False" /> 
                <column name="Name" isPk="False" isAutoInc="False" adoType="12" sqlType="nvarchar" length="50" isNull="True" /> 
                <class name="Product" check="-1" generated="True"
                    <field name="id" type="1" isPK="True" column="Id" valueType="System.Guid" /> 
                    <field name="name" type="1" isPK="False" column="Name" valueType="System.String" /> 
                </class> 
            </table> 
            <table name="'Product2Shop'" type="2" locked="False"
                <column name="ProductId" isPk="True" isAutoInc="False" adoType="-11" sqlType="uniqueidentifier" length="0" isNull="False" /> 
                <column name="ShopId" isPk="True" isAutoInc="False" adoType="-11" sqlType="uniqueidentifier" length="0" isNull="False" /> 
                <constraint name="FK__Product2S__Produ__5165187F" table="'Product2Shop'" dest="'Product'"
                    <column name="ProductId" /> 
                </constraint> 
                <constraint name="FK__Product2S__ShopI__52593CB8" table="'Product2Shop'" dest="'Shop'"
                    <column name="ShopId" /> 
                </constraint> 
                <field name="product2Shop" type="4" owner="'Product'" reference="'Shop'"
                    <mapping field="Product.id (Owner)" column="ProductId" /> 
                    <mapping field="Shop.id (Value)" column="ShopId" /> 
                </field> 
            </table> 
            <table name="'ProductPriceHistory'" type="1" locked="False"
                <column name="Id" isPk="True" isAutoInc="False" adoType="-11" sqlType="uniqueidentifier" length="0" isNull="False" /> 
                <column name="ProductId" isPk="False" isAutoInc="False" adoType="-11" sqlType="uniqueidentifier" length="0" isNull="False" /> 
                <column name="ShopId" isPk="False" isAutoInc="False" adoType="-11" sqlType="uniqueidentifier" length="0" isNull="False" /> 
                <column name="Price" isPk="False" isAutoInc="False" adoType="3" sqlType="money" length="0" scale="-1" isNull="False" /> 
                <column name="PriceDate" isPk="False" isAutoInc="False" adoType="12" sqlType="datetime2" length="27" isNull="False" /> 
                <constraint name="FK_P2S" table="'ProductPriceHistory'" dest="'Product2Shop'"
                    <column name="ProductId" /> 
                    <column name="ShopId" /> 
                </constraint> 
                <class name="ProductPriceHistory" check="-1" generated="True"
                    <field name="id" type="1" isPK="True" column="Id" valueType="System.Guid" /> 
                    <field name="price" type="1" isPK="False" column="Price" valueType="System.Decimal" /> 
                    <field name="priceDate" type="1" isPK="False" column="PriceDate" valueType="System.String" /> 
                    <field name="productId" type="1" isPK="False" column="ProductId" valueType="System.Guid" /> 
                    <field name="shopId" type="1" isPK="False" column="ShopId" valueType="System.Guid" /> 
                    <field name="product2Shop" type="2" isPK="False" reference="'Product2Shop'"
                        <mapping field="Product2Shop.productId" column="ProductId" /> 
                        <mapping field="Product2Shop.shopId" column="ShopId" /> 
                    </field> 
                </class> 
            </table> 
            <table name="'Shop'" type="1" locked="False"
                <column name="Id" isPk="True" isAutoInc="False" adoType="-11" sqlType="uniqueidentifier" length="0" isNull="False" /> 
                <column name="Name" isPk="False" isAutoInc="False" adoType="12" sqlType="nvarchar" length="50" isNull="True" /> 
                <class name="Shop" check="-1" generated="True"
                    <field name="id" type="1" isPK="True" column="Id" valueType="System.Guid" /> 
                    <field name="name" type="1" isPK="False" column="Name" valueType="System.String" /> 
                </class> 
            </table> 
        </tables> 
        <views /> 
        <procedures /> 
    </classGenerator> 
    <options> 
        <general mapTables="True" mapViews="False" /> 
        <sourcegeneration partial="True" /> 
        <allSchemata> 
            <schemata name="(default)" /> 
        </allSchemata> 
        <usedSchemata> 
            <schemata name="(default)" /> 
        </usedSchemata> 
        <mapping> 
            <identity explicitIDClass="False" /> 
            <class generateFKIDField="True" generateVersionField="True" /> 
            <procedure insert="False" update="False" delete="False" /> 
        </mapping> 
    </options> 
</openaccess> 
 
Thanks,
Ivan.
0
Ady
Telerik team
answered on 02 Jun 2010, 02:44 PM
Hi ie,

 I used your Reversemapping.config file and generated the classes and could compile the classes successfully. The 'product2Shop' reference field mapping (in the ProductPriceHistory class) is incomplete.
If you want a reference field which points to the Product2Shop table you will need to map the table to a class and not a join table. Since the 'Product2Shop' table is mapped as a join table it will not be available in the 'Type' dropdown list for the reference field.

Did you make any changes to the default values after executing the wizard?

Best wishes,
Ady
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
Design Time (Visual Designer & Tools)
Asked by
ie
Top achievements
Rank 1
Answers by
Ady
Telerik team
ie
Top achievements
Rank 1
Share this question
or