{"_id":"55435b69b7f4540d00fcef46","category":{"_id":"5543585f795b590d001dc89a","version":"553dec691a946a0d00ad6f2a","__v":9,"pages":["554358c8b7f4540d00fcef43","55435b69b7f4540d00fcef46","55435bf2795b590d001dc8a3","55435ec262b30e0d004b1706","555636f626e9bc0d0044ea81","55563946ea5e120d00188550","555639cc26e9bc0d0044ea8d","5561dd7bb40338210035f905","56bafe8ccec63e0d00f0d2eb"],"project":"553dec691a946a0d00ad6f27","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2015-05-01T10:41:35.279Z","from_sync":false,"order":1,"slug":"usage","title":"Usage"},"version":{"_id":"553dec691a946a0d00ad6f2a","project":"553dec691a946a0d00ad6f27","__v":2,"createdAt":"2015-04-27T07:59:37.477Z","releaseDate":"2015-04-27T07:59:37.477Z","categories":["553dec691a946a0d00ad6f2b","5543585f795b590d001dc89a"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1.0"},"project":"553dec691a946a0d00ad6f27","user":"54c4b05742190d0d00f5fbde","__v":2,"updates":[],"next":{"pages":[],"description":""},"createdAt":"2015-05-01T10:54:33.557Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"auth":"required","params":[],"url":""},"isReference":false,"order":2,"body":"In the previous examples, you have seen how to create entities *explicitly*, by calling the `Build()` and `BuildList()` methods. For the ultimate in terseness, you can omit these methods, and Dossier will *implicitly* call them for you. The one caveat is that you must explicitly declare the variable type rather than using the `var` keyword. \n\nSo, to create a single entity:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"Customer customer = new CustomerBuilder();\\n\\nCustomer customer = new CustomerBuilder()\\n\\t.WithFirstName(\\\"Matt\\\")\\n\\t.WithLastName(\\\"Kocaj\\\")\\n\\t.WhoJoinedIn(2010);\",\n      \"language\": \"csharp\"\n    }\n  ]\n}\n[/block]\nOr to create a list of entities:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"List<Customer> entities = BasicCustomerBuilder.CreateListOfSize(5);\\n\\nList<Customer> data = CustomerBuilder.CreateListOfSize(3)\\n  .All()\\n\\t.With(b => b.WithFirstName(generator.Generate().ToString()));\",\n      \"language\": \"csharp\"\n    }\n  ]\n}\n[/block]","excerpt":"","slug":"creating-entities-implicitly","type":"basic","title":"Implicit .Build() calls"}

Implicit .Build() calls


In the previous examples, you have seen how to create entities *explicitly*, by calling the `Build()` and `BuildList()` methods. For the ultimate in terseness, you can omit these methods, and Dossier will *implicitly* call them for you. The one caveat is that you must explicitly declare the variable type rather than using the `var` keyword. So, to create a single entity: [block:code] { "codes": [ { "code": "Customer customer = new CustomerBuilder();\n\nCustomer customer = new CustomerBuilder()\n\t.WithFirstName(\"Matt\")\n\t.WithLastName(\"Kocaj\")\n\t.WhoJoinedIn(2010);", "language": "csharp" } ] } [/block] Or to create a list of entities: [block:code] { "codes": [ { "code": "List<Customer> entities = BasicCustomerBuilder.CreateListOfSize(5);\n\nList<Customer> data = CustomerBuilder.CreateListOfSize(3)\n .All()\n\t.With(b => b.WithFirstName(generator.Generate().ToString()));", "language": "csharp" } ] } [/block]