Port existing code to entity framework