Home > .NET Object Database > Tipps and Tricks

Tipps And Tricks

SQL View Update

If you update one column on the view that's no problem. However if you update multiple columns on a view you'll get the error: "View or function is not updatable because the modification affects multiple base tables." This is a limitation of Microsoft SQL Server. However you simple can rephrase the statement as follows:

/* Throws exception: */
UPDATE View_Person SET NameFirst='Max', NameLast='Meyer'

/* Works fine: */
UPDATE View_Person SET NameFirst='Max' UPDATE View_Person SET NameLast='Meyer'


Strongly Typed Property Names

If you don't want to write the name of every property in every get and set method you can use the following code instead. (Reduces slightly performance). With StackFrame you can query the name of the current method automatically:

using System;

using System.Diagnostics;

using Signumsoft.ObjectDatabase;

                       

namespace HelloWorld

{

    public class Person : ObjectX

    {

        ...

        public string NameFirst

        {

            get

            {

                string fieldName =

                    new StackFrame().GetMethod().Name.Replace("get_", null);

                return GetValue<string>(fieldName, null);

            }

            set

            {

                string fieldName =

                    new StackFrame().GetMethod().Name.Replace("set_", null);

                SetValue(fieldName, value);

            }

        }

    }

}



SQL Select Distinct

Object Instances might appear multiple times in generated SQL views. Resolve it like this: Select Data from View with the following statemant:

SELECT DISTINCT * FROM View_Person