**var entity = entityRepository.FindById(entity.Id)**
//Load with properties
**var entity = entityRepository.FindById(entity.Id, x=> x.OtherEntity, t=>t.AnotherEntityCollection);**
//Parameterles.
**entityRepository.FindAll();**
//Get entities which SomeProperty = Predicate
**entity.Repository.FindAll(x=>x.SomeProperty == "Predicate");**
//Get entity and its Child Collection
**entity.Repository.FindAll(x=>x.ChildCollection)**
//Get entities which SomeProperty = Predicate and include Child Collection
**entity.Repository.FindAll(x=>x.SomeProperty= "Predicate" , t=>t.ChildCollection);**
//Entity without a parent
entity = new entity() { ... };
entityRepository.Add(entity);
//Child object that has parent
entity = new entity() { ... , parentId= 3 };
entityRepository.Add(entity);
//OR
//Child Object that has parent
entity = new entity() { ... };
parent = parentRepository.FindyById(parentId);
parent.ChildEntityCollection.Add(entity);
//With Entity Id
**someModelRepository.Remove(entity.Id);**
//With Entity
**someModelRepository.Remove(entity);**
//One-To-One Relation
**parent.Child = null;**
//One-To-Many Relation
**parent.ChildCollection.Remove(Child);**
//OR
**parent.ChildCollection.Clear()**
**try**
**{**
**using (unitOfWorkFactory.Create())**
**{**
//Add, Remove, Modify
**}**
**}**
**catch (ModelValidationException mvex)**
**{**
**foreach (var error in mvex.ValidationErrors)**
**{**
**ModelState.AddModelError(error.MemberNames.FirstOrDefault() ?? "", error.ErrorMessage);**
**}**
**}**
No comments yet.
Cheatography n. The art of mapping complex subjects into clear, instantly navigable reference guides.