EF5 and .net 4.5 - c#

I'm thinking about this scenario.
In desktop application I will create EF STE enity. App will be using EF 5 and .NET 4.0.
This entity will be send through WCF to server where will be .NET 4.5 and also EF5.
Is this supported scenario? (i'm failing to find anything useful) I would like to have performance benefits in .net 4.5 on server side.
Thank you.

If the desktop application is also doing things to a database I'm going to assume it's a different one than is on the server. You'll still want to convert complex entities into simpler ones. For instance if you have an entity that contains a list of other entities that you know already exist on the server, translate that into a message entity (by convention just append Message to the entity name i.e. EntityName -> EntityNameMessage) before sending it over the wire by selecting the Ids from the original entity when you translate, rather than the list's entire contents. This would be one way to gain performance.
Alternatively you're using the same database on the client and the server, which is probably a bad practice since you would have to recycle EF on the server every time the client updated an entity in its database, since EF wouldn't know about the change.

Related

Entity Framework Core pointing at multiple databases, depending on user?

I am a Java programmer learning C# on the job and I have inherited a C# stand alone web application using Entity Framework Core to talk to a Microsoft SQL backend.
Now we need to be able to specify which database instance the user wants to use at runtime (based on a table lookup), and due to the way the code is build I essentially need to be able to replace
dbContext.TableName.Where(....)....
with
dbContext.ChooseDatabase(...).TableName.Where(....)....
everywhere in the client code. The context is currently shared between all users, and there is not a session object in the client side of the code.
What is the best way to approach this?

Managing normalising a database over time using Entity Framework Core

We're just starting to move off of a legacy codebase and begin using .net and Entity Framework Core for most of our new software.
We've migrated our database from our old platform to SQL Server, but the data is old and poorly normalised. We cannot undertake a normalisation project all at once because of the potential impact on the (large) existing codebase in the legacy language, so we are adding primary and foreign key definitions to our database as we go, and regenerating our Entity Framework Core model from scratch as more tables become valid for the framework.
I feel like we're missing some important capabilities of Entity Framework Core by doing this, but I don't really know enough about the framework to identify what it is. I know the generated model lacks completeness (my question was prompted because a table with an Identity column did not have the column marked as ValueGeneratedOnAdd(); in fact that table does not appear in the OnModelCreating method at all) but I don't know whether that's an issue with the database or another mistake I'm making.
My question is: what capabilities are there within Entity Framework Core to manage a rapidly-evolving database model? What should I be doing for myself, and what should I be relying on the Scaffold-DBContext command for?
With EF Core, most of the things you will need will be done by Scaffold-DBContext. The only things it doesn't handle right now is DBQuery sets. You will have to manually code those. Other than that, everything else is handled pretty eloquently by the command.
As far as ValueGeneratedOnAdd(), the only time I have ever seen this as a problem has been Versioned tables. If you have a versioned table, Scaffold-DBContext will not add that to those fields and you must have those so you will have to manually add those to your code.

Can now use BreezeJS without having to use EF?

Previously you had to use Entity Framework as Breeze connected directly to the DbContext and that object did not exist elsewhere.
There is the notion of creating Metadata by hand(ie by T4)
I have access to the SQL server where every Table has its own crud usp (SSMS Tools Pack) the ashx does all the RMI into the DB, generates the json schema etc and the DTO service model. I have looked at WCF service layer (http://davybrion.github.io/Agatha/) but monolith EF seems to be everywhere. I have tried Angular I am quite happy to use ADO or Dapper.NET is there connectivity for BreezeJS is to a high performance back-end (Micro-ORM) or should I use Kendo DataSource (http://docs.telerik.com/kendo-ui/framework/datasource/overview). This is for a Hybrid Mobile App, that need frictionless data. Anyone else found an easy ClientSide/Server Side JSON Data integration system that is not so bloated?
Thanks in advance
Yes, you can use Breeze without EF. This needs to be promoted better.
The Breeze.ContextProvider package does not depend on EF. It has a ContextProvider class that handles turning the JSON from the client into server-side .NET entities. You subclass ContextProvider to implement the part that does the actual saving to the database.
breeze.server.net provides two implementations: Breeze.ContextProvider.EF for Entity Framework, and Breeze.ContextProvider.NH for NHibernate. You can look at these for inspiration about how to build the Dapper implementation.
One of the tricky bits is performing the add and delete operations in the right order. For instance, if I'm adding a Customer and some related Orders, the Customer needs to be added to the DB before the Orders. EF sorts the adds automatically, but NH does not, so we have a SortDependencies() method in NHRelationshipFixer. You may need to do something similar if your micro-ORM does not do it for you.
If you come up with an implementation for a micro-ORM, please consider contributing it to the community.

How to pass typed dataset objects using web services

I have a C# Winform application (.Net 3.5) which access a MSSQL server using typed DataSet objects.
currently, my whole application is working in one layer, and the client access directly to the DB using those typed DataSet objects.
I want to change my application to client-server model (which will use web-services for communication).
My question is:
How can I pass typed DataSet objects in the web-services?
For example,
I have a table of persons.
And I want my client side to be able to get specific person (using web-service), update its age, and save the change (again using web service).
Is it possible?
Thanks
Since you are using .Net, you should at least check out Entity Framework (the .Net ORM) prior to going with the 3rd party nHibernate. nHibernate might be fine, and might be the way to go, but you should at least compare it to Entity Framework first and have a reason for not using Entity Framework.
You should try something out like Hibernate. Which is an intermediate entity-based mapping between classes and database tables. The queries would be performed on the business side of the application (web service in your case) in the HQL language; which is very similar to regular SQL. I've personally used it multiple times with Java and it can be quite useful. Doing a brief internet search I found "NHibernate" which is a .NET specific version for Hibernate.
For my specific Java application, it is set up such that the GUI is not on the web-service, while basically everything else is. Then using a resource manager, created a "link" which pointed at the business side. All transactions were performed on the web-service, while they were being displayed on the client side.
So to answer your question; yes it is entirely possible.

Entity Framework 5 log database changes at runtime

In an ASP.NET 4.5 C# Entity Framework 5 Code First project I'd like to log the changes being made in the database at runtime (the logging has to be done in the asp.net app, not at the database). Previously, the SQL statements were built by the code, and those statements were simply logged. Now with EF, the object is retrieved via linq to entities, modified and
db.SaveChanges();
is being called. My first idea was to retrieve the actual SQL statements that EF sends to the DB -- this seems to be rather complex, however. I've found many "solutions" for displaying the SQL during debugging, but no simple way for the code to retrieve it at runtime.
So I'm looking for any solution that can log the changes being made (either the SQL being sent to the DB [preferred], or some other form of textual representation of the changes made to the object), and that doesn't require the inclusion of a number of complex debug libraries.
You should try FrameLog
https://bitbucket.org/MartinEden/framelog/wiki/Home
It is not clearly stated but it supports Entity Framework 5
I haven't tested this on EF 4.5 so it may need to be tweaked a bit, but I find for debugging purposes the extension method written at the bottom of this post:
http://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/2a50ffd2-ed73-411d-82bc-c9c564623cb4/
Gives me the correct output of my entities.SaveChanges() call. It doesn't require any external libraries and since it's written as an extension method it won't clog up your code.

Categories

Resources