Created
March 2, 2012 18:41
-
-
Save ioleksiy/1960303 to your computer and use it in GitHub Desktop.
AcroDB. How to use
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [AcroDbEntity] | |
| public interface ICar | |
| { | |
| Guid ID { get; set; } | |
| [AcroColumnStringLength(80)] | |
| string Name { get; set; } | |
| int YearOfAssembly { get; set; } | |
| [AcroColumnStringLong] | |
| string Description { get; set; } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using (var manager = AcroDataContext.Go) | |
| { | |
| //Object creation and filling | |
| var car = manager.Provide<ICar>().Create(); | |
| car.Name = "Mitsubisi Lancer"; | |
| car.YearOfAssembly = 2009; | |
| car.Description = "Mitsubisi Lancer, a bit new, but red one"; | |
| //Saving an entity | |
| manager.Provide<ICar>().Save(car); | |
| //Don't forget to submit changes | |
| manager.SubmitChanges(); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using (var manager = AcroDataContext.Go) | |
| { | |
| //We will find all cars assembled in 2009 and will show it to console | |
| var collection = manager.Provide<ICar>() | |
| .Query.Where(c => c.YearOfAssembly == 2009); | |
| foreach (var car in collection) | |
| Console.WriteLine(car.Name); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using (var manager = AcroDataContext.Go) | |
| { | |
| //We will find one car assembled in 2009 and which is first in our db | |
| var car = manager.Provide<ICar>() | |
| .Query.Where(c => c.YearOfAssembly == 2009).First(); | |
| Console.WriteLine(car.Name); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using (var manager = AcroDataContext.Go) | |
| { | |
| //Object search and changing | |
| var car = manager.Provide<ICar>() | |
| .Query.Where(c => c.YearOfAssembly == 2009).First(); | |
| car.Name = "Mitsubisi Lancer (Red)"; | |
| manager.Provide<ICar>().Save(car); | |
| manager.SubmitChanges(); | |
| //Deleting an entity | |
| manager.Provide<ICar>().Delete(car); | |
| //Don't forget to submit changes even after delete | |
| manager.SubmitChanges(); | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The article http://www.oleksiy.pro/2010/03/26/acrodb-how-to-use/