Although where the show starts, David and Mary Margerette are technichally married because James married Snow White in the fairytale world, due to the evil queen's curse, they do not remember the fact that they are married. Also, the way the show works, it shows through flashbacks, James and Snow White's life before they were married.
Prince James was forced by his father, to marry a princess named Abigail. James didn't want to marry her, because he doesn't love her. He was upset with his life. until he met Snow White who was running away from the evil queen, Regina. The two seem attracted to each other, but then Snow White robs James, leading the two to fight. The two eventually team up, to get Jame's satchel back from trolls, and after a battle with the trolls, James and Snow White develope feelings for each other. James wishes to marry Snow, instead of Abigial, but doesn't have any choice.
After many obstacles seperating them, the two are eventually reunited, and get married, and have a baby named Emma. However, the evil queen threatens to create a curse that would destroy everybodys happy ending. James and Snow worry about this, and learn that Emma is the only one who can save them. They send Emma through a magic wardrobe, so that she isn't affected by the curse. Right after they send Emma through the wardrobe, Regina activates the curse, and the curse puts James in a coma.
28 years later, where the show starts, James, thinking his name is David Nolan, wakes up from a coma, and meets Mary Margerette. The two are instantly attracted to each other, not knowing that they are already married. They wish to be together, but a woman named Katherine (Princess Abigail) comes and claims that she is married to David, leaving Mary Margerette depressed.
David eventtually has an affair with Mary Margerette, and soon leaves Katherine for her. Katherine is at fist upset, but eventually accepts it, as she realizes, David loves Mary Margerette more than her.
After many more obstacles, David and Mary Margerette eventually get back together, and when the curse breaks, the two are thrilled to remember who they really are.