The apostles didn't at all link Christ to David through Mary -- they did it through his legal adoptive father, Joseph. Both genealogies go from David to Joseph. One involves an episode of a brother raising up seed, legally, for his brother. The other is a pure bloodline.
Oka, thank you. I remember reading somewhere that +Jospeh's line was something less than clear, but I could have misunderstood.