Here's my problem:
I am creating a Blackberry application that access's my data via a web service.
The web service is using entity framework which was created for my web application.
I use the SUN wireless toolkit stub generator to create the code and classes to access the web service from the Blackberry application. The stub generator does not like dates and fields that return collections so I usally have to create new classes manually that deal with this.
Idea:
I want to be able to generate these classes automatically from my entity framework model?
What is the best way to do this?
I would like to make this generic. Something similar to the POCO generator would be ideal
Thanks
From what I know about Entity Framework, it has some XML-based schema description. You can write relatively simple XSLT transformation, which will transform this XML into a set of classes suitable for transmitting over the wire.
Related
I'm writing a simple ASP.NET WebForms tool that writes data back to our company's Dynamics NAV instance via a web service. I'm working with multiple tenants for the different sales regions. This means that I have a separate web service for each tenant.
Since the web services are exposed as separate classes in .NET and the classes do not share the same base class, it now looks like I have to write the same code all over again for each tenant since the types don't match up.
Does anyone know of a solution to this problem? I've considered using generic methods but I can't generate objects of the generic types. I also can't narrow down the type because, again, the generated classes don't share a base class or implement the same interface.
I'm looking for a way to communicate between different C# (only) apps via gRPC. Is there any way to provide service definitions and contracts by C# interfaces and POCO classes (attributed by ProtoMember, etc.), instead of creating a proto file and generating a code out of it? I need this to work on .net framework 4.7.2, i.e. working with grpc.core rather than grpc.dotnet.
PS: The main idea why I want this is to avoid the code generation part which seems to be excessive here. Also need to be able to specify custom attributes to my POCO classes, like DisplayAttribute and stuff.
Alright, looks like I found the answer https://github.com/grpc/grpc-dotnet/issues/68
protobuf-net.Grpc seems like the lib I was looking for
You can also check ServiceStack gRPC which provides code-first development.
In my project I am using OData v3 and v4 (ASP.NET Web API with Entity Framework in the back).
Currently I built a client using the Visual Studio tools.
But is there another way? Do I really have to build a client based on the $metadata and the toolset?
Is it possible to share my model (contract) by a shared library and build a client like this:
var client = new ODataClient<MySharedModel>(uri);
MySharedModel.Product product =
client.Products.Where(p => p.Category.Name == "Vegetables").FirstOrDefault();
The model can be a set of my own DTO objects which I can map to the equivalent entity framework objects.
My goal is, to share a well-documented model (source code XML documentation) with additional logic such as a ToString implementation and additional properties. Further more I save a additional step: generating a client (this sucks when you build and publish all your packages automatically on TFS Build server).
Is this possible for OData v3 or OData v4?
OData has recently started reviving and the team is regularly releasing new updates of the OData Connected Service entity generator, so you might want to consider giving it another shot.
You can definitely reuse the same model, but then you'd lose client-specific features that are generated for you, for example a dedicated container with all entity-sets as properties, collection properties exposed as ObservableCollection<T>, as well as self-tracking entities, as well as others.
All classes are generated as partial classes, so you can always extend them by adding methods into your own parts, which can, for this matter, also be shared classes.
Regarding the documentation, it's not supported at the moment, but this has been suggested and seems to be considered for future development.
Anyway, it's definitely possible, and shouldn't be to hard using your own entities.
To learn how to facilitate OData client access using your client POCOs, I'd recommend generating the model once and keep the code off your project or as excluded files, just for the reference, so you can mimic a similar functionality that works for you. That was the most helpful way to me.
Additionally, you will benefit from having a look at the documentation and the API reference docs, which has been a bit refreshed lately.
I'm writing a java client for a WCF REST service. This service uses lots of different data classes for communication, transmitted in JSON. On my side, I'm using the Gson lib to do handle the serialization of these classes. However for this to work, I obviously need the Java definitions of the used C# classes.
Currently I'm writing these by hand: I check the C# class definitions, check which property has a [DataMember] annotation and create a corresponding java class with those properties. This is a terrible solution: it's slow, tedious and difficult to keep these classes up to date manually.
What tools / method should I use to generate these classes somehow from their C# counterparts? Is writing some .net console app that generates java classes using reflection the only solution?
You can try a tool like wsdl4j to create a proxy java file and just use the class definitions in it.
Yesterday I worked on a project where I upgraded to Entity Framework 4 with the Repository pattern. In one post, I have read that it is necessary to turn off the custom tool generator classes and then write classes (same like entites) by hand. That I can do it, I used the POCO Entity Generator and then deleted the new generated files .tt and all subordinate .cs classes. Then I wrote the "entity classes" by myself.
I added the repository pattern and implemented it in the business layer and then implemented a WCF layer, which should call the methods from the business layer. By calling an Insert (Add) method from the presentation layer and everything is OK. But if I call any method that should return some class, then I get an error like (the connection was interrupted by the server).
I suppose there is a problem with the serialization or am I wrong? How can by this problem solved?
I'm using Visual Studio S2010, Entity Framework 4, C#.
UPDATE:
I have uploaded the project and hope somebody can help me! link text
UPDATE 2:
My questions:
Why is POCO good (pros/cons)?
When should POCO be used?
Is POCO + the repository pattern a good choice?
Should POCO classes by written by myself or could I use auto generated POCO classes?
Why is POCO good (pros/cons)?
Work with EF4, NH and few others -ORM
When should POCO be used?
Depends on usage
Is POCO + the repository pattern a good choice?
For WCF
POCO- You have track changes manually,
STE Automatic Change Tracking is done.
Should POCO classes by written by myself or could I use auto generated POCO classes?
T4 would be better choice.
Regarding your WCF serialization issues, in the t4 template, we needed to set the ProxyCreationEnabled = false; on the ContextOptions
http://msdn.microsoft.com/en-us/library/system.data.objects.objectcontextoptions.proxycreationenabled.aspx
For POCO serialization you'll need the ProxyDataContractResolver.
You may wnat to check out this MSDN Walkthrough article on building a custom attribute that you can apply to your service contract to serialize the POCO proxy types.