Crainiate Community

Support and discussion for users of Crainiate component software products
Welcome to Crainiate Community Sign in | Join | Help
in Search

A few queries about usage of the Update() Method

Last post 12-18-2006 10:08 AM by Archer. 8 replies.
Page 1 of 1 (9 items)
Sort Posts: Previous Next
  • 12-14-2006 11:54 AM

    A few queries about usage of the Update() Method

    Hi,

    I have a question with regards to the usage of Update() method.

    The following piece of code returns a concurrency error. I'm new to this, is this the way it should be?

    Query<Person> qry=new Query<Person>();
    qry.Context = context;
    qry.Execute();

    foreach ( Person P in qry.Results )
    {
    if ( P.Name == "Test" )
    {
    P.Context = context;
    P.Vat = 17.5M;
    P.Update(); // This line raises a concurrency exception.
    }
    }


    The following code works fine but I don't understand why:
    if ( P.Name == "Test" )
    {
    P.Context = context;
    P.Select();
    P.Vat = 17.5M;
    P.Update(); // No exception
    }

    One last issue: The code above updates the corresponding record but sets Vat column to 18!! The column defined as Decimal(18,2) on my SQL2005 database.

    Thanks in advance
    • 82.45.255.253
  • 12-14-2006 6:29 PM In reply to

    Re: Confusion about usage of the Update() Method

    Hi,

    [Edit]

    Could you please post the code for the Person class?

    Thanks, James
    • 81.153.80.231
  • 12-14-2006 7:06 PM In reply to

    Re: Confusion about usage of the Update() Method

    Hmm. I think I'm beginning to understand but still not clear why the result set shouldn't have the values. Also the result set has null Context and I have to set it manually. I'm just assuming here that since I set the context of the query, the result set will have the same context.

    Btw, the Person class is as follows:

    class Person : Table
    {
    private int _Id;
    private string _Name;
    private decimal _Vat;

    [PrimaryKey(1,1)]
    public int Id
    {
    get
    {
    return _Id;
    }
    set
    {
    _Id = value;
    }
    }

    [Column, MaximumLength( 30 )]
    public string Name
    {
    get
    {
    return _Name;
    }
    set
    {
    _Name = value;
    }
    }

    [Column]
    public System.Decimal Vat
    {
    get
    {
    return _Vat;
    }
    set
    {
    _Vat = value;
    }
    }

    public Person()
    {
    }
    public Person( string Name, Decimal Vat, Context C )
    {
    this.Name = Name;
    this.Vat = Vat;
    this.Context = C;
    }
    }


    • 82.45.255.253
  • 12-15-2006 7:02 PM In reply to

    Re: A few queries about usage of the Update() Method

    I ran a test to make sure that query results were being assigned a context.

    In my test, the result objects did have a context. When assigning a new context, the concurrency would however be removed, thus causing the concurrency error.

    If you do continue to see a null context issue, then please let me know the steps to reproduce so that we can fix the problem.

    For the decimal property, a fixed point decimal is created with zero decimal places. The procedures will also use this data type.

    An attribute will be added to allow you to specify the scale and precision in the next release, in the meantime you could change the procedures and table by hand, or use a floating point data type, such as float, double etc.
    • 81.153.80.231
  • 12-15-2006 7:46 PM In reply to

    Re: A few queries about usage of the Update() Method

    Following piece of code returns objects with null context:

    class Program
    {
    public static SqlContext context;
    public static SqlDeployment deployment;

    static void Main( string[] args )
    {
    context = new SqlContext();
    context.Server = "(local)";
    context.Database = "TestDB";
    context.Prefix = "";
    context.Integrated = true;

    deployment = new SqlDeployment();
    deployment.Context = context;
    deployment.DeploymentType = DeploymentType.Deploy;
    deployment.DeploymentMode = DeploymentMode.Update;
    deployment.Deploy( Assembly.GetAssembly( typeof( Person ) ) );

    Query<Person> qry = new Query<Person>();
    qry.Context = context;
    qry.Execute();

    if ( qry.Results.Count == 0 )
    {
    Person P;
    P = new Person( "John", 5M, context );
    P.Insert();
    P = new Person( "Beverly", 11.5M, context );
    P.Insert();
    P = new Person( "Mark", 1.12M, context );
    P.Insert();
    }
    else
    foreach (Person P in qry.Results)
    if (P.Context == null)
    Console.WriteLine(String.Format("Context is null for {0}", P.Name ));
    }
    }

    • 82.45.255.253
  • 12-16-2006 11:44 AM In reply to

    Re: A few queries about usage of the Update() Method

    We have identified a problem in our unit tests which provided a context automatically.

    The context should be created by the query processor, but isnt. We will create a fix for this and post an update urgently.

    Thank you for bringing this to our attention.
    • 81.153.80.231
  • 12-16-2006 12:38 PM In reply to

    Re: A few queries about usage of the Update() Method

    Ok, great. Looking forward to that.

    Thank you.
    • 82.45.255.253
  • 12-17-2006 11:50 PM In reply to

    Re: A few queries about usage of the Update() Method

    This issue has now been addressed with the release of build 1.0.2542. Please see the following post for more details:

    http://support.crainiate.net/Forums/forums/176/ShowPost.aspx#176
    • 81.153.80.231
  • 12-18-2006 10:08 AM In reply to

    Re: A few queries about usage of the Update() Method

    Excellent! Works like a charm.
    • 82.45.255.253
Page 1 of 1 (9 items)