Tuesday, September 6, 2011

Invalid object name 'KeyTable'. lightspeed error

  private static LightSpeedContext<ModelUnitOfWork> _context;
        private void Form1_Load(object sender, EventArgs e)
        {

            _context = new LightSpeedContext<ModelUnitOfWork>("Development");
        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            using (var uow = _context.CreateUnitOfWork())
            {
                Movie movie1 = new Movie();
                movie1.Title = "Hackers (1995)";
                movie1.Description = "A young boy is arrested by the US Secret Service "
               +"for writing a computer virus and is banned from using a computer until "
 +"his 18th birthday.";
                uow.Add(movie1);     // it gives error on this statement. Due to some identity
                                    //  creation problem.
                uow.SaveChanges();
                //var comment1 = new Comment();
                //comment1.Body = "Best hackers movie ever!";
                //comment1.PostedBy = "John-Daniel Trask";
                //comment1.Movie = movie1;
                //uow.SaveChanges();

            }
        }
This error message is generated because you are using the keyboard's identity. The method of identity is how LightSpeed ​​generate identifiers for entities and, by default, uses the standard keyboard. This requires a table called "table of keys" (there is a script for this in the LightSpeed ​​installation directory  in the folder of providers).



Configuring identity generation
Identity generation is set on the LightSpeed context, either in code or by using the LightSpeed configuration
section in the .config file for your application.
            LightSpeedContext.IdentityMethod = IdentityMethod.KeyTable;

            // or

            LightSpeedContext.IdentityMethod = IdentityMethod.Guid;

            // or

            LightSpeedContext.IdentityMethod = IdentityMethod.GuidComb;

            // or

            LightSpeedContext.IdentityMethod = IdentityMethod.Sequence;

            // or

            LightSpeedContext.IdentityMethod = IdentityMethod.MultiSequence;

            // or

            LightSpeedContext.IdentityMethod = IdentityMethod.IdentityColumn;

When using the KeyTable, Sequence or MultiSequence types you can also fine tune the
LightSpeedContext.IdentityBlockSize. The default value is 10 and in most applications you will not need to
change this default.

Configuring IdentityBlockSize

LightSpeedContext.IdentityBlockSize = 20;


If you do not use the method of identity KEYTABLE please set an appropriate method for setting
up your LightSpeedContext the file. Config. No information about the different methods in the help
file in the screencast to get started and some of the samples.

You can read the help online here to know more about this in details:
http://www.mindscape.co.nz/Help/LightSpeed/Help%20Topics/LightSpeed/IdentityGeneration.html

No comments :

Post a Comment