Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 150 lines (117 sloc) 4.861 kB
8d521e5 @emiliotorrens Readme
authored
1 ## MongoMapper.NET
2
3 A .NET Object Mapper for MongoDB over MongoDB C# Driver
4
9341869 @emiliotorrens Update README.md
authored
5
8d521e5 @emiliotorrens Readme
authored
6
cd60195 @emiliotorrens Update README.md
authored
7 ### Dependencies
8
9341869 @emiliotorrens Update README.md
authored
9 * [MongoDB distributions] (http://www.mongodb.org/downloads)
10 * [MongoDB Driver for CSharp] (http://github.com/mongodb/mongo-csharp-driver)
11 * [NUnit] (http://www.nunit.org), [NUnit for Visual Studio] (http://nunitforvs.codeplex.com)
cd60195 @emiliotorrens Update README.md
authored
12
6b40285 @emiliotorrens Update README.md
authored
13 ### Defining the Model
9a9985b @emiliotorrens Update README.md
authored
14
43dc8c2 @emiliotorrens Update develop
authored
15 [Serializable]
be93e86 @emiliotorrens Update README.md
authored
16 [MongoKey(KeyFields = "Code")]
17 public class Country: MongoMapper
18 {
19 [MongoDownRelation(ObjectName = "Person", FieldName = "Country")]
20 public string Code { get; set; }
21 public string Name { get; set; }
9a9985b @emiliotorrens Update README.md
authored
22
be93e86 @emiliotorrens Update README.md
authored
23 [MongoPropertyValidator(PropertyName="Code")]
24 public void CodeIsUp(string CountryCode)
25 {
26 if (CountryCode != CountryCode.ToUpper())
27 throw new Exception(String.Format("{0} must be {1}", CountryCode, CountryCode.ToUpper()));
28 }
9a9985b @emiliotorrens Update README.md
authored
29 }
30
43dc8c2 @emiliotorrens Update develop
authored
31 [Serializable]
be93e86 @emiliotorrens Update README.md
authored
32 [MongoKey(KeyFields = "")]
33 [MongoIndex(IndexFields = "ID,Country")]
34 [MongoIndex(IndexFields = "Name")]
35 [MongoMapperIdIncrementable(IncremenalId = true, ChildsIncremenalId = true)]
36 public class Person : MongoMapper
37 {
38 public Person()
39 {
40 Childs = new List<Child>();
41 }
42
43 public string Name { get; set; }
44 public int Age { get; set; }
45 public DateTime BirthDate { get; set; }
46 public bool Married { get; set; }
47 public decimal BankBalance { get; set; }
48
49 [MongoUpRelation(ObjectName = "Country", FieldName = "Code")]
50 public string Country { get; set; }
51
52 [MongoChildCollection]
53 public List<Child> Childs { get; set;}
9a9985b @emiliotorrens Update README.md
authored
54 }
55
6b40285 @emiliotorrens Update README.md
authored
56 ### Work with the Model
57
367a2f3 @emiliotorrens Update README.md
authored
58 Country c = new Country {Code = "es", Name = "España"};
59 try
60 {
61 c.Save();
62 }
63 catch(Exception ex)
64 {
65 Assert.AreEqual(ex.GetBaseException().GetType(), typeof(ValidatePropertyException));
66 c.Code = "ES";
67 c.Save();
68 }
69
6b40285 @emiliotorrens Update README.md
authored
70 c = new Country { Code = "UK", Name = "Reino Unido" };
71 c.Save();
367a2f3 @emiliotorrens Update README.md
authored
72
73 c = new Country { Code = "UK", Name = "Reino Unido" };
74 try
75 {
76 c.Save();
77 }
78 catch (Exception ex)
79 {
80 Assert.AreEqual(ex.GetBaseException().GetType(),typeof(DuplicateKeyException));
81 }
82
a6df820 @emiliotorrens Añadido ejemplo de eventos al Readme
authored
83 Country c2 = new Country { Code = "US", Name = "Francia" };
84 c2.OnBeforeInsert += (s, e) => { ((Country)s).Name = "Estados Unidos"; };
85 c2.Save();
6b40285 @emiliotorrens Update README.md
authored
86
b1082f7 @emiliotorrens Añado un Test con el Codigo del Readme
authored
87 Country c3 = new Country();
88 c3.FillByKey("US");
a6df820 @emiliotorrens Añadido ejemplo de eventos al Readme
authored
89 Assert.AreEqual(c3.Name, "Estados Unidos");
90
6b40285 @emiliotorrens Update README.md
authored
91 List<Country> countries = new List<Country>();
92 countries.MongoFind();
93 Assert.AreEqual(countries.Count, 3);
94
95 countries.MongoFind(Query.Or(MongoQuery.Eq((Country co) => co.Code, "ES"), MongoQuery.Eq((Country co) => co.Code, "UK")));
96 Assert.AreEqual(countries.Count, 2);
97
98 Person p = new Person
99 {
100 Name = "Pepito Perez",
101 Age = 35,
102 BirthDate = DateTime.Now.AddDays(57).AddYears(-35),
103 Married = true,
5d31558 @emiliotorrens Agregados ejemplo de relations y serverupdate al Readme
authored
104 Country = "XXXXX",
6b40285 @emiliotorrens Update README.md
authored
105 BankBalance = decimal.Parse("3500,00")
106 };
107
5d31558 @emiliotorrens Agregados ejemplo de relations y serverupdate al Readme
authored
108 p.Childs.Add(new Child() { ID = 1, Age = 10, BirthDate = DateTime.Now.AddDays(57).AddYears(-10), Name = "Juan Perez" });
6b40285 @emiliotorrens Update README.md
authored
109
5d31558 @emiliotorrens Agregados ejemplo de relations y serverupdate al Readme
authored
110 try
111 {
112 p.Save();
113 }
114 catch (Exception ex)
115 {
116 Assert.AreEqual(ex.GetBaseException().GetType(), typeof(ValidateUpRelationException));
117 p.Country = "ES";
118 p.Save();
119 }
120
b1082f7 @emiliotorrens Añado un Test con el Codigo del Readme
authored
121 p.ServerUpdate(Update.PushWrapped("Childs", new Child() { ID = 2, Age = 2, BirthDate = DateTime.Now.AddDays(57).AddYears(-7), Name = "Ana Perez" }));
2bc8d9d @emiliotorrens Update README.md
authored
122
123 List<Person> persons = new List<Person>();
124 persons.MongoFind("Childs.Age",2);
125 Assert.AreEqual(persons.Count, 1);
6b40285 @emiliotorrens Update README.md
authored
126
9a9985b @emiliotorrens Update README.md
authored
127
e423e59 @emiliotorrens Update README.md
authored
128 ### You can find examples in the Test Project
5685f8a @emiliotorrens Update README.md
authored
129
130 * [Class Definition](https://github.com/emiliotorrens/MongoMapper.NET/tree/master/EtoolTech.MongoDB.Mapper.Test.NUnit/Classes)
9a0a1da @emiliotorrens Update README.md
authored
131 * [Find] (https://github.com/emiliotorrens/MongoMapper.NET/blob/master/EtoolTech.MongoDB.Mapper.Test.NUnit/FindTest.cs)
132 * [Write] (https://github.com/emiliotorrens/MongoMapper.NET/blob/master/EtoolTech.MongoDB.Mapper.Test.NUnit/InsertModifyDeleteTest.cs)
133 * [Incremental ID] (https://github.com/emiliotorrens/MongoMapper.NET/blob/master/EtoolTech.MongoDB.Mapper.Test.NUnit/IncrementalIdTest.cs)
134 * [Relations](https://github.com/emiliotorrens/MongoMapper.NET/blob/master/EtoolTech.MongoDB.Mapper.Test.NUnit/RelationsTest.cs)
135 * [Events] (https://github.com/emiliotorrens/MongoMapper.NET/blob/master/EtoolTech.MongoDB.Mapper.Test.NUnit/EventsTest.cs)
136 * [Extension Methods] (https://github.com/emiliotorrens/MongoMapper.NET/blob/master/EtoolTech.MongoDB.Mapper.Test.NUnit/ExtensionTest.cs)
137 * [Original Version] (https://github.com/emiliotorrens/MongoMapper.NET/blob/master/EtoolTech.MongoDB.Mapper.Test.NUnit/OriginalObjectTest.cs)
5b67a60 @emiliotorrens Update README.md
authored
138
139 ### Change Log
140
9341869 @emiliotorrens Update README.md
authored
141 * [30/12/2011] (http://bit.ly/uy80RE)
142 * [05/01/2012] (http://bit.ly/yfcsn4)
143 * [02/02/2012] (http://bit.ly/AfGfKC)
144 * [14/02/2012] (http://bit.ly/zvnk0F)
145 * [07/03/2012] (http://bit.ly/wMX6Ha)
146 * [20/03/2012] (http://bit.ly/GAIbez)
d0cea93 @emiliotorrens Update master
authored
147 * [18/07/2012] (http://bit.ly/M9gqOp)
17da904 @emiliotorrens Merge branch 'master' of github.com:emiliotorrens/MongoMapper.NET
authored
148
5685f8a @emiliotorrens Update README.md
authored
149
Something went wrong with that request. Please try again.