ADO. NET is. NET with the core of database interoperability, and the Ado.net entity database is enhanced. NET application and database, through ado.net Entity Data Model, we can easily and strongly type data interoperation with the underlying database. Greatly facilitates the design personnel, thus also enhances the database operation security. a very special problem has recently been encountered in using the domain data service to Silverlight [the results in the application are not the same as the results of the database] and after repeated trials, the root causes of the problem are finally found. That's ado.net. The Entity Data Model relies on entity keys, and its queries generate unique result sets for entity keys.
Now let's look at the specific process and how it is handled:
To manipulate the database tables, a vw_desksandusers view of two atomic tables was established in the database view, which was designed to connect existing user tables and desk data, so I did the following T-SQL view, as follows:
The query results obtained in SQL Server 2008 are as follows:
That is to say, the expected results, [this step is successful]. Next step.
Step Two: Create a new Silverlight business application silverlightdomaindb that will support WCF RIA services in the generated projects. This is necessary to support the services in the Silverlight domain.
Step three: Add a new item in the Web project that ado.net the Entity Data model, select the corresponding database connection and datasheet, view, and stored procedure in the wizard, and then generate the corresponding Entity data type and context, and get it. EDMX's model diagram. As shown below:
As prompted by Visual Studio 2010, it generated two entity keys for us: deskid,isplaying (This is two fields in the desk table); Now rebuild the project.
Step Fourth: Add Web domain service items based on the entity model. (In this step you need to add the appropriate table and metadata information)
Step fifth: In the Silverlight project, drag the DataGrid in the vw_desksandusers of the data source to Home.xaml, complete, Debug. Did not get the results above, but instead generated the following datagrid:
After careful observation, it turns out it was ado.net. The result set in the Entity Data Model relies on entity keys, meaning that the Silverlight domain service generates the above data with the Deskid as the unique key, based on the unique result set of the entity key.
Processing:
According to the above analysis, to get the expected results, you must set the appropriate entity key, in order not to affect the underlying SQL database, we need to modify. EDMX the entity key in the Model diagram (right-click to select or uncheck entity key):
Now rebuild the project and run the program, and the program gets the expected results.
The
Silverlight business application, as a template for data display, provides a friendly interface for database rendering, and because of its optimized database handling, we have to consider some of their nuances when we use them [due to the visual I didn't see a LINQ-Generated T-SQL query in studio, so I just offered a simple solution, and I think it's deep because the T-SQL statements generated in a LINQ query are different from the T-SQL statements in the database.