In this article I will be creating a Data Access Layer using WCF. I will be using MEF to export the data from the Data Access Layer class and then import it.MEF offers a nice way to create Composable applications where I can easily import and export data.Created a ADO.Net Entity Data Model as shown in diagram below:Create a new WCF Service as shown below:Two files would be added to the solution as DataService and IDataService.cs.Add a method GetArticles() to IDataService.cs:[ServiceContract]public interface IDataService{ [OperationContract] IEnumerable GetArticles();}Implement the method in DataService.cs:public IEnumerable GetArticles(){ PublishingCompanyEntities context = new PublishingCompanyEntities(); var article = from art in context.Articles select art.Title;
return article;}Creating a Data Class:
Creating another class App
Please note that to add the Export and Import attributes you need to add a reference to System.ComponentModel.Composition. Call the App class now.static void Main(string[] args){ App a = new App(); a.Run(); Console.ReadKey();}
It works. Happy Coding.
You need to be a premium member to use this feature. To access it, you'll have to upgrade your membership.
Become a sharper developer and jumpstart your career.
$0
$
. 00
monthly
For Basic members:
$20
For Premium members:
$45
For Elite members: