See the question and my original answer on StackOverflow

CodeFluent does not really support object keys that are not nullable, because the implied semantics would be somehow strange. When you delete an object, from an OO perspective, the object is now null, it's identifier does not exist any more, it's not set to a specific 0 or other value. You will probably run into other problems with tweaking the model like this.

That being said, one way to change this behavior is to use the "persistenceUnlink" attribute on the property involved, directly in the XML file. Unfortunately the graphical modeler does not support this (ancient) attribute and will override it everytime you modify the model and save it back using the GUI.

So, what you can do is use a custom aspect to automatically apply this attribute on properties where you want it. Here is a sample code for such an aspect (note the aspect runs on startup because it's really based on XML, not on the in-memory model contrary to most aspects):

<cf:project xmlns:cf="http://www.softfluent.com/codefluent/2005/1" defaultNamespace="unlink">
  <cf:pattern name="Unlink Aspect" namespaceUri="http://www.example.com/unlink" preferredPrefix="ul" step="Start">
    <cf:message class="_doc">
       Sample aspect that removes auto unlink in delete procedures
    </cf:message>
    <cf:descriptor name="unlink" targets="Property" defaultValue="true" displayName="Unlink" typeName="boolean" description="Determines if this property will be unlinked during delete" category="Unlink Aspect" />
  </cf:pattern>

  <?code @namespace name="System" ?>
  <?code @namespace name="System.Xml" ?>
  <?code @namespace name="CodeFluent.Model" ?>

<?code
      // use a special utility method to get all elements
      // with the given attribute in a given namespace URI
      var properties  = Project.Package.RootModelPart.SelectElements("unlink", "http://www.example.com/unlink", false);
      foreach(var property in properties)
      {
        // here we set a special attribute not supported by the GUI designer in Visual Studio
        property.SetAttribute("persistenceUnlink", "false");
      }

?>
</cf:project>

What you must do is:

  • save this code as a file, for example "unlink.xml" somewhere around your project files.
  • in the graphical modeler, right-click on the "Aspects" node of the CodeFluent project, and choose "Add existing aspect", browse to your unlink.xml file (it should display the aspect metadata), and press ok.
  • go back to the design surface in the graphical modeler, click on the property you want to remove persistence link, go to the Visual Studio property grid, choose the blue "aspects and producers properties" tab, and set "Unlink" to False that should now be displayed (default is true).
  • rebuild, and the stored procedure code should not contain links for this relation any more.