Hello folks,

today i want to show you some tipps which you can need when you first work with the DomainService Class.

Tip 1:
Problem: My Entities/Tables are not shown at the creation Context

Solution: You have to Create your Web Project first. After that you should see all your Entities/Tables of your Database in the context.

Tip 2:
Problem: When you create a new DomainService two files were created. *.cs and a *.metadata.cs file.
If you have selected several tables, the complete code will saved in one file. This can be very confusing.
I love it to have all structured and clear. So i create for each Entitie a new File.

Solution:
For example you create a DomainService with the name “DomainService” which contain two Entities “ExampleTable” and “AnotherTable”.
Now open the DomainService.cs file. In this file you see something like this(shorten Version):

DomainService.cs

What you now have to do is to create two new cs files. The names should be like this:

DomainService.ExampleTable.cs
DomainService.AnotherTable.cs

Now Copy the complete DomainService.cs file in it and delete

[EnableClientAccess()] in each file

After that you have to make the class to a partial class, so you have to change it like this:

public partial class DomainService : LinqToEntitiesDomainService

Now delete in each file the other Entities Methods.

The two files should look like this:

DomainService.ExampleTable.cs

DomainService.AnotherTable.cs

If you have done it in both files you now need to edit the DomainClass.cs file.

Make it even to partial and delete the Methods in the class so it lookes like this:

DomainService.cs

Now you are finished. This is a lot clearer for you now. The Compiler still see this as one file.
If you want to append your Service with a new IQueryable Method you dont have to search through the complete file.

Additional you can create a seperate folder for each DomainService.

Tip 3:

Problem: How to make Query over many Tables?

Solution:
The magic word is “Include”.
First you have to add the [Include] attribute in the metadata class to a EntityCollection of your Table you want to access.

Now you have to have to include the Table in the Query.

Now all Data of “AnotherTable” and “AnotherTable.TableStatus” were included and you can access them.

Tip 4:

Problem: How can i check what my DomainService returns and debug it?

Solution:
This is very simple, but a good trick.

If you now add a breakpoint at “return query;” you can see the result of the query and which data were given back.