Database Reference
In-Depth Information
Figure 11-12. A WebProduct entity in our model
To expose this database function for your queries, do the following:
1.
Right-click the .edmx file in the Solution Explorer, and click Open With XML Editor. This
will open the .edmx file in the XML Editor.
Insert the code in Listing 11-19 just below the <Schema> tag in the storage models section
of the .edmx file. This defines the functions in the storage layer.
2.
Listing 11-19. Defining Our Function in the Storage Layer
<Function Name="ISNULL" ReturnType="varchar" BuiltIn="true" Schema="dbo">
<Parameter Name="expr1" Type="varchar" Mode="In" />
<Parameter Name="expr2" Type="varchar" Mode="In" />
</Function>
3.
Insert into and query the model using code similar to the pattern shown in Listing 11-19.
Listing 11-20. Using the ISNULL() Function in an eSQL and LINQ Query
class Program
{
static void Main(string[] args)
{
RunExample();
}
static void RunExample()
{
using (var context = new EFRecipesEntities())
{
var w1 = new WebProduct
{
Name = "Camping Tent",
Description = "Family Camping Tent, Color Green"
};
var w2 = new WebProduct { Name = "Chemical Light" };
var w3 = new WebProduct
{
Name = "Ground Cover",
Description = "Blue ground cover"
};
 
Search WWH ::




Custom Search