Sunday, January 9, 2011

How can we use XML files to map stored procedures with .NET classes?

n case you have stored procedures in your project you can use ‘Function’ XML element to define your stored procedure name in the XML file. The client code does not change for binding the datacontext and XMLMappingsource object as below.

<?xml version="1.0" encoding="utf-8"?>

<Database Name="TstServer" xmlns="http://schemas.microsoft.com/linqtosql/mapping/2007">

<Table Name="dbo.Customer" Member="WebAppMappingXML.clsCustomer">

<Type Name="WebAppMappingXML.clsCustomer">

<Column Name="CustomerId" Member="CustomerId" />

<Column Name="CustomerName" Member="CustomerName" />

<Column Name="CustomerCode" Member="CustomerCode" />

</Type>

</Table>

<Function Name="dbo.sp_getCustomerCode" Method="getCustomerByCode">

<Parameter Name="CustomerCode" Parameter="" />

<ElementType Name="clsCustomer" />

</Function>

</Database>

No comments:

Post a Comment