cancel
Showing results for 
Search instead for 
Did you mean: 

OData and self referencing entity

Former Member
3,882

Hi,

I'm currently Setting up an OData-service with version 16.0.02003 and have a problem with a "self referencing" entity when creating the service reference in Visual Studio.

I have created a table like this:

drop table if exists Stammdaten.ErledigteArbeiten;
create table Stammdaten.ErledigteArbeiten (
     GUID uniqueidentifier not null Default newid(),
     PARENTID uniqueidentifier null,
     BEZEICHNUNG varchar (60) ,
     TEXT Long varchar,
     contraint PK_ErledigteArbeiten Primary key (GUID),
);
alter table Stammdaten.ErledigteArbeiten
add foreign key FK_ErledigteArbeiten_ErledigteArbeitenParent (PARENTID)
references Stammdaten.ErledigteArbeiten (GUID)
on update restrict
on delete cascade;


The corresponding osdl-file is quite simple:

service Namespace "Engel" {
     entity "Stammdaten"."ErledigteArbeiten";
}


When I try to create a service reference in Visual Studio I get the following error:

Fehler 0042: Name ErledigteArbeiten kann nicht in Typ Engel.ErledigteArbeiten verwendet werden. Elementnamen dürfen nicht mit dem einschließenden Typ übereinstimmen.

Taking a look at the metadata there are two NavigationProperties one with Name "ErledigteArbeiten" and one with "FK_ErledigteArbeiten_ErledigteArbeitenParent". So it's clear that the first one leeds to the error.

IMO this is a bug in the odata producer code ... is there a workaround or what can I do to get this working?

TIA

Armin

Accepted Solutions (1)

Accepted Solutions (1)

philippefbertrand
Participant

This has been fixed for build 16.0.0.2030. We now ensure that types can not have properties with the same name as the containing type.

Association names also could have the same name as a complex type or entity type. OSDL files with such name conflicts now produce errors and generated navigational properties and associations are given better names.

Answers (1)

Answers (1)

philippefbertrand
Participant
0 Kudos

There is certainly an issue. The generation code allows the navigational property to have the same name as its containing property. While some OData clients are less strict, Visual Studio does not allow it.

The work around is to define all associations in the OSDL file.

I suggest you contact support to help us understand the impact of this issue.