none
Specified cast invalid RRS feed

  • Question

  • With this wonderfully  helpful error message, I am unable to determine the problem when updating the object. Every time I do .SubmitChanges(), I receive the exception.

    I have the following DB schema for the tables used.



    The source code for attempting to insert or modify a record is

    1                // 
    2                // Grab the feature ID that is related to this plugin. 
    3                // 
    4                var pluginFeatureId = (from spf in this.SecurityPluginFeatures 
    5                                       where spf.Key == feature.Key && 
    6                                             spf.SecurityPluginID == pluginId 
    7                                       select new { spf.SecurityPluginFeatureID }).SingleOrDefault(); 
    8 
    9                // 
    10                // If the feature ID is null, then this feature was not found in the database 
    11                // and is not valid. Throw an exception to indicate that we have somehow  
    12                // received invalid data. 
    13                // 
    14                if (pluginFeatureId == null) 
    15                { 
    16                    throw new InvalidDataException(string.Format("Unable to the find the feature ID for plugin key {0} and feature key {1}", pluginId, feature.Key));  
    17                } 
    18 
    19                // 
    20                // Check to see if this is an entry that we are modifying or  
    21                // it has already been saved to the database. 
    22                // 
    23                var objectPluginFeature = (from sopf in this.SecurityObjectPluginFeatures 
    24                                           where sopf.SecurityObjectName == objectName && 
    25                                                 sopf.SecurityPluginFeatureID == pluginFeatureId.SecurityPluginFeatureID 
    26                                           select sopf).SingleOrDefault(); 
    27 
    28                SecurityObjectPluginFeature f = objectPluginFeature
    29 
    30                // 
    31                // If we did not find an entry for this user with the feature ID, 
    32                // then create the new entry. 
    33                // 
    34                if (objectPluginFeature == null) 
    35                { 
    36                    objectPluginFeature = new SecurityObjectPluginFeature(); 
    37                    this.SecurityObjectPluginFeatures.InsertOnSubmit(objectPluginFeature); 
    38 
    39                    // 
    40                    // Set the SecurityPluginFeatureID and SecurityObjectName since 
    41                    // this is a new entry. 
    42                    // 
    43                    objectPluginFeature.SecurityObjectName = objectName
    44                    objectPluginFeature.SecurityPluginFeatureID = pluginFeatureId.SecurityPluginFeatureID; 
    45                } 
    46 
    47                // 
    48                // Set the bit to indicate if this feature is allowed or denied. 
    49                // 
    50                objectPluginFeature.Allow = feature.HasAccess; 
    51 
    52                // 
    53                // Save the changes. 
    54                // 
    55                this.SubmitChanges(); 

    Anyone have a clue as to what I am doing incorrectly here.
    Wednesday, December 24, 2008 3:50 PM

All replies

  • one instance I have seen where this error can occur (and just did for me!) is if you add an association between tables which does not reference the key of the parent table.
    Thursday, October 13, 2011 3:49 AM