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

Foreign key constraint on null column in MSSQL 2005

1 Answer 88 Views
Development (API, general questions)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
James Denning
Top achievements
Rank 1
James Denning asked on 17 Nov 2009, 01:39 PM
HI
In a forward-mapped schema, is there any way I can get OpenAccess to create foreign key constraint on a columns that allows NULLS? SQL Server 2005 supports this but the only option I can find in OpenAccess is the "Throw an exception ion commit if the field is null" option but this sets the corresponding column to NOT NULL.
What I need is that the Reference field's datasource is a reference table say for example Countries - and I want the database to enforce the referential integrity for tables where the Country entry is not mandatory.

I could of course alter the schema post-build but that is painful to maintain and hard to automate.

James

1 Answer, 1 is accepted

Sort by
0
PetarP
Telerik team
answered on 18 Nov 2009, 03:37 PM
Hello James Denning,

By default Telerik OpenAccess ORM uses algorithms to decide whether a foreign key constraint makes sense or not. In your case you can use this setting in the backend configuration to manually override our logic:
<dbNullForeignKey>true</dbNullForeignKey>

This will create your foreign key constraint. The backend configuration should look something similar to this after you have added this setting.
<backendconfigurations>
      <backendconfiguration id="mssqlConfiguration" backend="mssql">
        <dbNullForeignKey>true</dbNullForeignKey>
        <mappingname>mssqlMapping</mappingname>
      </backendconfiguration>
    </backendconfigurations>
Please let us know if this solution works for you.

Best wishes,
Petar
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Development (API, general questions)
Asked by
James Denning
Top achievements
Rank 1
Answers by
PetarP
Telerik team
Share this question
or