This is a migrated thread and some comments may be shown as answers.

Fluent Mapping and Version

1 Answer 54 Views
Development (API, general questions)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Roderik
Top achievements
Rank 1
Roderik asked on 19 Oct 2011, 04:37 PM
Dear Telerik, 

I am trying to use automatic versioning via telerik fluent mapping but I can't seem to get it to work. 

My basic example: 

public class Dog
{
    public int ID { get; set; }
    public string Name { get; set; }
    public long Version { get; set; }
}

which has the following mapping: 

MappingConfiguration<Dog> dogConfiguration = new MappingConfiguration<Dog>();
dogConfiguration.MapType().ToTable("dogs");
dogConfiguration.HasProperty(p => p.ID).IsIdentity(KeyGenerator.Autoinc);
dogConfiguration.HasProperty(p => p.Version).IsVersion().IsNotNullable();
preparedConfigurations.Add(dogConfiguration);

and the following unittest: 

Punt4FluentContext dbContext = new Punt4FluentContext(
   dbConnection, sqlConfiguration);
 
Dog dog = new Dog();
dog.Name = "Droopy";
dbContext.Add(dog);
dbContext.SaveChanges();
 
Punt4FluentContext dbContext2 = new Punt4FluentContext(
   dbConnection, sqlConfiguration);
 
dbContext2.GetAll<Dog>().First().Name = "Barkinson";
dbContext2.SaveChanges();

Gives the following result in the database: 

i_d: 1
nme: Barkinson (so, it did save it twice)
vrsion: 0 <-- I expected 2 here!

What I wish to achieve is make the version field auto increment every time the entity is saved (which in this case is two times). I assumed the method IsVersion() could be used for this. Is this possible or should I implement this functionality in the domain layer?

Kind regards,
Roderik Steenbergen

1 Answer, 1 is accepted

Sort by
0
Serge
Telerik team
answered on 20 Oct 2011, 04:08 PM
Hello Roderik,

 You also need to specify that the class uses version as its concurrency mechanism. You can do so with code that look like: 

dogConfiguration.WithConcurencyControl(OptimisticConcurrencyControlStrategy.Version)
         .ToTable("dogs");

However I think that this can be automatically inferred and we will be planning on improving this behaviour. 

I hope this is helpful. 

Best wishes,
Serge
the Telerik team

NEW and UPDATED OpenAccess ORM Resources. Check them out!

Tags
Development (API, general questions)
Asked by
Roderik
Top achievements
Rank 1
Answers by
Serge
Telerik team
Share this question
or