public override int InsertFriend(Friend friend)
        {
            var context = new FriendsEntities();
            var obj = new tblFriends_Friends();
            context.AddTotblFriends_Friends(obj);
            friend.CopyToObject(obj);

            if (friend.Groups != null)
            {
                foreach (var group in friend.Groups)
                {
                    var item = new tblFriends_Groups {Id = group.Id};
                    context.AttachTo("tblFriends_Groups", item);
                    obj.Groups.Add(item);
                }
            }

            context.SaveChanges();
            return obj.Id;
        }
 private static Friend Convert(tblFriends_Friends obj)
 {
     if (obj == null)
     {
         return null;
     }
     var friend = new Friend(obj.Id, obj.CreatedDate, obj.CreatedBy, obj.ModifiedDate, obj.ModifiedBy);
     friend.CopyFromObject(obj);
     friend.Groups = new List<Group>(Convert(obj.Groups));
     return friend;
 }