Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

Diff of /System.Data.SQLite.Linq/SQL Generation/DmlSqlGenerator.cs [1dc57d] .. [463047] Maximize Restore

  Switch to side-by-side view

--- a/System.Data.SQLite.Linq/SQL Generation/DmlSqlGenerator.cs
+++ b/System.Data.SQLite.Linq/SQL Generation/DmlSqlGenerator.cs
@@ -29,7 +29,7 @@
     internal static string GenerateUpdateSql(DbUpdateCommandTree tree, out List<DbParameter> parameters)
     {
       StringBuilder commandText = new StringBuilder(s_commandTextBuilderInitialCapacity);
-      ExpressionTranslator translator = new ExpressionTranslator(commandText, tree, null != tree.Returning);
+      ExpressionTranslator translator = new ExpressionTranslator(commandText, tree, null != tree.Returning, "UpdateFunction");
 
       // update [schemaName].[tableName]
       commandText.Append("UPDATE ");
@@ -81,7 +81,7 @@
     internal static string GenerateDeleteSql(DbDeleteCommandTree tree, out List<DbParameter> parameters)
     {
       StringBuilder commandText = new StringBuilder(s_commandTextBuilderInitialCapacity);
-      ExpressionTranslator translator = new ExpressionTranslator(commandText, tree, false);
+      ExpressionTranslator translator = new ExpressionTranslator(commandText, tree, false, "DeleteFunction");
 
       // delete [schemaName].[tableName]
       commandText.Append("DELETE FROM ");
@@ -101,8 +101,7 @@
     internal static string GenerateInsertSql(DbInsertCommandTree tree, out List<DbParameter> parameters)
     {
       StringBuilder commandText = new StringBuilder(s_commandTextBuilderInitialCapacity);
-      ExpressionTranslator translator = new ExpressionTranslator(commandText, tree,
-          null != tree.Returning);
+      ExpressionTranslator translator = new ExpressionTranslator(commandText, tree, null != tree.Returning, "InsertFunction");
 
       // insert [schemaName].[tableName]
       commandText.Append("INSERT INTO ");
@@ -244,10 +243,11 @@
       /// <param name="preserveMemberValues">Indicates whether the translator should preserve
       /// member values while compiling t-SQL (only needed for server generation)</param>
       internal ExpressionTranslator(StringBuilder commandText, DbModificationCommandTree commandTree,
-          bool preserveMemberValues)
+          bool preserveMemberValues, string kind)
       {
         Debug.Assert(null != commandText);
         Debug.Assert(null != commandTree);
+        _kind = kind;
         _commandText = commandText;
         _commandTree = commandTree;
         _parameters = new List<DbParameter>();
@@ -260,6 +260,7 @@
       private readonly List<DbParameter> _parameters;
       private readonly Dictionary<EdmMember, DbParameter> _memberValues;
       private int parameterNameCount = 0;
+      private string _kind;
 
       internal List<DbParameter> Parameters { get { return _parameters; } }
       internal Dictionary<EdmMember, DbParameter> MemberValues { get { return _memberValues; } }
@@ -671,6 +672,11 @@
 
       public override void Visit(DbScanExpression expression)
       {
+        string definingQuery = MetadataHelpers.TryGetValueForMetadataProperty<string>(expression.Target, "DefiningQuery");
+        if (definingQuery != null)
+        {
+          throw new NotSupportedException(String.Format("Unable to update the EntitySet '{0}' because it has a DefiningQuery and no <{1}> element exists in the <ModificationFunctionMapping> element to support the current operation.", expression.Target.Name, _kind));
+        }
         _commandText.Append(SqlGenerator.GetTargetTSql(expression.Target));
       }