{"metadata":{"image":[],"title":"","description":""},"api":{"url":"","auth":"required","params":[],"results":{"codes":[]}},"next":{"description":"","pages":[]},"title":"Implicit .Build() calls","type":"basic","slug":"creating-entities-implicitly","excerpt":"","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]","updates":[],"order":2,"isReference":false,"hidden":false,"sync_unique":"","link_url":"","link_external":false,"_id":"55435b69b7f4540d00fcef46","category":{"sync":{"isSync":false,"url":""},"pages":["554358c8b7f4540d00fcef43","55435b69b7f4540d00fcef46","55435bf2795b590d001dc8a3","55435ec262b30e0d004b1706","555636f626e9bc0d0044ea81","55563946ea5e120d00188550","555639cc26e9bc0d0044ea8d","5561dd7bb40338210035f905","56bafe8ccec63e0d00f0d2eb"],"title":"Usage","slug":"usage","order":1,"from_sync":false,"reference":false,"_id":"5543585f795b590d001dc89a","version":"553dec691a946a0d00ad6f2a","__v":9,"createdAt":"2015-05-01T10:41:35.279Z","project":"553dec691a946a0d00ad6f27"},"version":{"version":"1.0","version_clean":"1.0.0","codename":"","is_stable":true,"is_beta":false,"is_hidden":false,"is_deprecated":false,"categories":["553dec691a946a0d00ad6f2b","5543585f795b590d001dc89a"],"_id":"553dec691a946a0d00ad6f2a","createdAt":"2015-04-27T07:59:37.477Z","project":"553dec691a946a0d00ad6f27","__v":2,"releaseDate":"2015-04-27T07:59:37.477Z"},"githubsync":"","project":"553dec691a946a0d00ad6f27","user":"54c4b05742190d0d00f5fbde","createdAt":"2015-05-01T10:54:33.557Z","__v":2}

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]