WCF Data services or something else? - wcf

For a WPF client and Sql Server database application, I plan to use WCF data services for passing data between client and the database but I find the WCF client too limited in its abilities. Complex LINQ queries with JOINS etc. cannot be sent over to the server.
Is there another techonology that I should use here which supports complex LINQ queries from client to the server?

It's not entirely correct that you can't join data using OData (a.k.a. WCF Data Services). It's just that LINQ to OData does not support join syntax. However you can still retrive results from intersection of multiple tables using either Expand method or simply by specifying a relationship in a select clause. For example, if you have a table User with relationship to Phone table, you can write "from u in ctx.User.Expand("Phone")...", or you can write "from u in ctx.User select new { u.Name, u.Phone }", and it will retrive Phone collection.
I am not aware of any other RESTful LINQ provider that would support querying SQL data.

Related

Query Builder vs. ORM?

What is the difference between a query builder and an ORM that developers use in their backend server-side code/logic for interacting with their database? It seems like the query builder can fulfill the goal of coding in the same language you are choosing to write the backend server-side code/logic to work with the database. However, I don't understand why an ORM comes in the picture then.
SQL query returns records (scalars) that do not automatically load more data if needed.
ORM can return you a Java object (say Person) with actual working methods that can load more data from database (without writing more queries explicitly).
For example if you call person.getAddress() it can return Address object that's just loads from database on the fly. Without writing new "select address" query.
Whatever is returned form SQL query (builder) does not work like that.

How can I join tables from different databases in Azure SQL (SAAS)?

Having the older application that joins SQL tables from different databases like this:
SELECT a.value, b.value
FROM databaseA.dbo.tableA AS a
JOIN databaseB.dbo.tableB AS b
ON a.thekey == b.thekey
Being 3rd party, we have to accept the decision of the main implementor for the customer to use the license Azure SQL SAAS (Software As A Service; I am new to that, sorry if some terms are incorrect).
Is it possible to have databaseA and databaseB (that part is possible, checked through SSMS) in the Azure SQL and do the same JOIN (that part is unknown to me)?
I tried, but it failed. I do not know if something more have to be done to make the other database visible from each of the databases, or if it is not possible at all.
If it is not possible, what is the recommended technique to replace the old SQL code?
As you comment said: "I understand that it is different than working within one physical SQL Server. On the other hand, the different servers is probably related to possible replication. Is that correct? ", yes, you're right.
For Azure SQL database(PSSA), we only can use the elastic query to achieve the cross database query:
The elastic query feature (in preview) enables you to run a
Transact-SQL query that spans multiple databases in Azure SQL
Database. It allows you to perform cross-database queries to access
remote tables, and to connect Microsoft and third-party tools (Excel,
Power BI, Tableau, etc.) to query across data tiers with multiple
databases.
Note:
Make sure the primary database have the permission to access the remote databases. Add the the client IP to their database firewall. The remote database can be in different Azure SQL Server.
If you are using Azure SQL managed instance and Azure SQL Server on Azure VM, you can run this across query like on-premise SQL Server.

Can I use the $expand query operator in an Azure Mobile Service that does not use Code First / Entity Framework?

I'm using a javascript-based Azure Mobile Service, so no Web API / Entity Framework / Code First. I'm just using the Azure portal to create the tables and columns. I've noticed that there's no way to define strong relationships between tables. I have created columns that reference other columns. But unlike Entity Framework, this does not create true foreign key relationships between tables.
I've read that one can use the $expand ODATA operator to return related data:
http://zimmergren.net/technical/extending-windows-azure-mobile-services-queries-to-include-relational-data-and-optional-metadata
...but the MSDN documentation for the Azure Mobile REST API does not contain the $expand operator:
https://msdn.microsoft.com/en-us/library/azure/jj677199.aspx
Does this mean that relational queries are not possible without using an Entity Framework based Azure Mobile Service? Is the $expand operator only available for .NET-based Azure Mobile Services (not javascript-based)?
The $expand query operator is not supported in the Node.js backend for Mobile Services. However, you could certainly modify your Read backend scripts to return data from the related tables.
See this document for more information on implementing joins in your backend code: https://azure.microsoft.com/en-us/documentation/articles/mobile-services-how-to-use-server-scripts/#joins
You should also make sure you optimize your SQL queries: https://azure.microsoft.com/en-us/documentation/articles/mobile-services-sql-scale-guidance/

show relationships like Access

Is there a way to show table relationships as can be done in Access? Consider two tables:
Services
serviceid
application id
Application
application id
application name
I have already set up the diagram.
When opening the table service id I want to see the related application details like in Access.
Is this possible?
First of all, you an always use access to connect to SQL Server and see relationships through it.
The built in database diagram feature will also show relationships, as you describe. You can find it under the database in question in the diagrams node.
Here is an article about different options to produce an ERD.
Update:
In order to see results, I would suggest using access to connect to SQL Server, as described in the link above.
The SQL Server GUI does not have this facility, and if you want to see results from several tables you need to write the SQL queries that will generate the wanted data.
You could also create a VIEW:
CREATE VIEW ServicesApplication AS
SELECT S.ServiceID, S.ApplicationID, A.ApplicationName
FROM Services AS S
LEFT JOIN Applications AS A
ON S.ApplicationID = A.ApplicationID
That way you can always access the coupled data easily by manipulating the ServicesApplication view instead of the separate tables.
SQL 2008 doesn't have anything built in to provide that functionality. Almost sounds like you're looking to trouble shoot an application by looking at database entries...if thats true I'd recommend learning tsql well enough to write these statements as you need and not rely on another application to provide a visual interface. heh, if I'm completely wrong with that, ignore me :)
If you still want the 3rd party application route...I beleive TOAD has that functionality within it, though I've never connected it to a MS SQL 2008 server before. There are other third party applications out there that will provide this functionality, though I imagine they aren't all free. If you're looking for a free solution and already have Access going, Oded probably has the best idea here...connect MS access to the SQL 2008 server (linked tables) and use MS access to provide the features you want from ms access :)

Different databases using WCF dataservice

I have multiple SQL Server databases with the same schema. I would like to use one WCF data service (Rest service) to access the different databases.
How can I accomplish this so the client can pass in the correct database name or connection string?
You could define some query string parameters, something like:
http://YourServer/YourService/SomeUrl?database=MyDatabase1
and then in your server-side code, use that database=MyDatabase1 to dynamically build the connection string, that you then use to open a connection to the database. Shouldn't be too hard, I think!