WCF to Database Connectivity - c#

I am developing a businees application, which queries lots of record.
Which connectivity is good to retrieve?
1. LINQ to SQL or
2. LINQ to Entity or
3. RIA Service or
4. Others ?
Your help is greatly appreciated.

If you're creating a WCF service to expose a database to other programs, you could try WCF Data Services. With this, consumers of your service can use LINQ syntax to send complex queries to the service, which will execute them on the database and return the results REST-style, formatted in an XML dialect called OData that can be read by any XML parser--or transparently read and converted into objects by a WCF Data Services client.

Related

stateless API DB connection pattern

I am writing a (C#) stateless Rest api that returns data from a MS SQL server. It replaces a curently existing JAVA API that uses a lot of hardcoded queries to access the data.
Inside the api I'm building I'll need to have the controllers be able to target multiple databases. There is no session management not are there any authentication issues
What is a good approach for handling data access?
one option is to create all the connection objects for each request. I worry that this would cause quite some overhead. Another option is to use a singleton for each database connection.
Any advice on this matter is welcome

Which transaction manager will be used in the WCF

I am going through the transactions exist in wcf service but seeking some more clarification on this. I am not sure about which transaction manager wcf will use fo r following scnarios
1) If the wcf service is performing insert in table of one sql server database and delete from table of another sql server database(In same or different server)
2) If the same wcf service is performing insert in table of one sql server database and delete from table oracle database.
3) If wcf service calling 2 different wcf service performing operation on same sql server base database.
Kindly help me providing some understanding on this situations
Please refer to the following tutorials:
http://www.codeproject.com/Articles/570915/TutorialplusonplusUnderstandingplusTransactionsplu
http://www.codeproject.com/Articles/38793/Steps-to-Enable-Transactions-in-WCF

Cannot materialize complex or primitive type - WCF Data services

i use WCF Data services along with Entity framework to talk to the SQL Server database.
The data is not directly accessed through the ORM but instead ,the stored procedures are used to fetch and insert data.
I do a function import on the Entity framework and invoke them through the Web get calls from the WCF Dataservice.Most of the times these procedures return collection of Complex types(generated from EF).
This is how i execute from my asp.net mvc app
Context.Execute<T>("<service uri>", "GET",true);
Here is the error i get everytime
Cannot materialize a collection of a primitives or complex without the
type being a collection.
Does the latest WCF Data services client does not support collection of complex types.
I am using the latest version of WCF Data services client which is 5.5
I had the same problem as yours and it solved when I changed the third parameter of Execute method (is single value) to false.
Hope this helps you.
Kamen Velikov

How do i send DataSet's table /List of objects to client app?

Hi to all good people out there.
My server c# app has a database stored in .sdf file. It loads data in dataset and then list of objects. It connects to c# client app through sockets.
Right now to send a table i do something like this: table -> tobytes -> socket -> totable.
Is there any way i could easily send a dataset's table/a list of objects to client app?
Or maybe a sql server is an answer? But my server app needs to do much more than just being a database.
Or it will just take way more time than simple "tobytes" and "totable" methods and i shouldnt even care?
Please, give me an adivice in wich way to dig :)
ASP.NET (a.k.a. ASMX web services) is very easy to set up on the server, and ASMX web services are very easy to connect to from a .NET client application. You can write web services that return DataSets or lists of objects or whatever you like.
If you are using Visual Studio you could use the Web Service Software Factory
That way you can create an ASMX or WCF Service, includes designing your service with diagrams, so that you only need to code the business logic, and it's pretty easy to connect to a service that way (just check that you download the right version for your IDE)

Get only new entities from dataservice to client (feed?)

I've just getted started with WCF Data Services, so I appologize if I do not make sense.
I'm creating an online event logger/viewer. To do this I have created an ado.net entity data model and a wcf data service. This works fine, and I'm able to add Events to my service.
I'm now working on creating a windows client to browse the events and I was wondering if there is any approach to updating the client with new events on a regular basis. As there will be a large amount of events it seems ineffective to download all the events for each and every refresh.
To provide more information, I can mention the following:
1. A custom TraceListener class in software A posts events to the data service.
2. Since wcf data services can act as a data source, I elected to go for this approach instead of a regular web service.
3. I'm currently creating the client in WPF.
I'm looking forward to any answers to this question.
Thanks,
Stefan
WCF Data Services exposes your data using the OData protocol. This means that your client can easily query your data service using LINQ.
Per request that the client sends to the server, keep a timestamp. Next request, ask only for those events that occurred after the timestamp, using a LINQ query on your service reference-generated proxy.
var newEvents = myServiceRef.Events.Where(x => x.Timestamp >= lastTimestamp);
See also http://www.odata.org/ for more on the OData protocol, and http://msdn.microsoft.com/en-us/library/ee622463.aspx for more on using LINQ to access WCF Data Services.

Categories