Casing strategy on custom serializer is not picked up by linq provider - azure-cosmosdb

We need properties on a document that are polymorphic, so to enable this, we use a custom CosmosSerializer implementation that uses TypeHandling.Auto of Newtonsoft.Json. This works fine - actually, this serializer is an internal class in the Cosmos SDK, internal to "easy" the migration towards System.Text.Json.
Unfortunately, as we are using camel casing in the serialization towards the documents, things go wrong when using an item queryable, as the linq provider does not seem to "respect" the serialization setup, and the query is using capital casing which leads to results that are always empty.
When setting up the camel casing with CosmosSerializationOptions, this is not the case. So clearly the usage of the custom serializer is the cause of this issue.
Is anyone aware of a solution to this problem? Google tells me that I should decorate the properties used in linq queries with JsonProperty attributes, but they are not picked up it seems.

Ok, in the end, the solution is to add a CosmosLinqSerializerOptions while requesting an ItemLinqQueryable from the container, which allows you to specify the naming policy as well.

Related

What Symfony2 bundle is better for Neo4j integration?

https://github.com/klaussilveira/neo4j-ogm-bundle
https://github.com/jadell/neo4jphp
I am looking for more stable/ more active and wanted to see if you any one had experience with either one of them?
Neo4jPHP is a simple REST client. You don't get any object mapping from it. If you don't like using ORMs and prefer to do your own querying/lookups, it is probably more your style.
Neo4j-OGM is a wrapper around Neo4jPHP that adds in ORM-type capabilities, annotations on your domain classes and a repository pattern. If you have ever used Doctrine or Propel, you will recognize the style and syntax.
My opinion: if you are used to using an ORM or ODM, go with Neo4j-OGM. If you like to do more tweaking and "bare-metal" optimizations, go with Neo4jPHP.

Custom .NET Attribute to Check Method Return Type

At my company we use MVC.NET and Entity Framework to perform a SQL connection. I was wondering if there is a way to create a custom attribute on a class that will create warnings if the return type of a method is not IEnumberable? The idea is to avoid the developers defaulting to a collection making the function less generic.
.Net attributes are evaluated at runtime, and would not be useful for giving warning as the developers are churning out code. You can probably look at static analysis tools like FxCop / StyleCop so that these warnings are shown during compile time. In your particular case you might have to write a Custom Rule which will make the check.
Write a unit test checking the return type, rather than an attribute or anything else. That way you wont uglify your code.

ASP.NET SPA with a legacy domain objects

Looking at the Single page application beta in the MVC 4 I don't see how I can use my legacy domain objects as the model. It seems to require that the model use the entity framework to using DbDataController to get the data etc.
I do not understand the entity framework so I am probably missing something.
How can I use my legacy domain (with it's own DAL) in the SPA of MVC 4?
This was answered by somebody else in an ASP.NET forum.
You won't be able to use anything other than EF if you want to use some of these RAD tools. However, SPA builds on top of MVC, so you should be able to build your own version rather easily. The important components would be building a DataController on top of ApiController and a js consumer for the service provided by your DataController. It's possible that if you were to format your models in the same format as the EF output (I think it's just OData) you could use upshot.js, as well and only have to implement a DataController to format your domain models.
I will add the following after working with it for a couple of days that you could, theoretically, use it if the following are handled/fixed by you and future versions of the SPA.
You can create a controller that inherits from System.Web.Http.Data.DataController (and maybe even ApiController). The objects it returns then must just have a property decorated with the System.ComponentModel.DataAnnotations.Key() attribute. I can get the views to work fine but some of the more advance features, like grouping, I am having problems with.
Readonly property will not be returned I guess because of a problem with the current JSON serializer used. Should be fixed.
Of course the entire object will be serialized which can be very problematic if your domain objects are complex with child objects. Especially if some of those objects have serialization issues of their own.
Related to the complex serialization the current JSON serializer cannot handle circular references in the domain objects referenced.
I have also run into problems getting update/deletes/inserts being posted back when using my own Controller that inherits from System.Web.Http.Data.DataController (the examples use DBDataController).

I am needing to change the table schema without reloading the app domain (EF Model Caching Issue)

I have a custom implementation of a multi tenant code first system basically SQL Schema Divisions of the tenants. I am using the ToTable method to map the schema correctly on the first call, but as I have read about the model being cached changing the schema on the second call do a different tenant does not work. Is there any ways in EF 4.1 to disable the caching or to rebuild the model every time.. Yes i know this is not great for performance. Thanks for any help..
Although it is an old question, but for all those who face this issue and end up finding this question for a possible solution. Here it goes...
Initially caching could be turned off by setting the "CacheForContextType" property of the ModelBuilder to ‘false’ in the OnModelCreating method. This method is defined in DBContext as virtual and needs to be overridden. But in EF 4.1 this property has been removed, since model creation is an expensive process and the Microsoft team wanted to promote a better pattern. Check this link
It seems like the Build() command on the ModelBuilder is what you're looking for.
modelBuilder.Build().Compile().CreateObjectContext...

Using multiple ObjectContexts in Entity Framework 4 with the repository/uow pattern

i am using EF4 and StructureMap in an asp.net web application. I am using the repository/unit of work patterns as detailed in this post. In the code, there is a line that delegates the setup of an ObjectContext in global.asax.
EntityUnitOfWorkFactory.SetObjectContext(() => new MyObjectContext());
On the web page code-behind, you can create a generic repository interface like so ...
IRepository<MyPocoObject> ds = ObjectFactory.GetInstance<IRepository<MyPocoObject>>();
My question is what is a good approach to refactoring this code so that I can use more than one ObjectContext and differentiate between them in the code-behind? Basically i have two databases/entity models in my application and need to query them both on the same page.
The Unit of Work is used to manage persistence across multiple repositories, not multiple object contexts.
You're not going to be able to persist changes across multiple contexts using a unit of work, as the UoW is simply implemented as a wrapper for a ObjectContext. Therefore, you'll need two unit of works.
Overall, things are going to get messy. You're going to have two OCs newed up and disposed each HTTP request, not to mention transaction management is going to be a nightmare.
Must you have two ObjectContexts? What is the reasoning for this? If it's for scalability, don't bother; it's going to be too painful for other things like your repository, unit of work and http scope management.
It's hard to provide good advice without seeing how you have your repositories set up.
Try creating wrapper classes for each object context, each implementing IUnitOfWork and a secondary unique interface (IEfSqlContext1, etc which represents one of your models/contexts).
Then you can inject whichever context you want.
As I said though, try and avoid having two EDMX/Contexts. It's more trouble than it's worth.

Resources