Conditional compilation for EF Core at design time - entity-framework-core

I have a custom projection method, and you can see here that it's giving me an error, but only when doing the EF Core build.
While I can't figure out how to actually solve that issue, I am hoping I can temporarily avoid it. I've been trying to find a way to identify when EF Core is doing its build, and just wrap the offending code in a conditional.
I've been looking at the RuntimeInformation class, but it doesn't seem to indicate anything useful.
Is it possible to conditional something like this?

Related

How to update gobuffalo models with pop?

I'm starting a project and already check how useful is gobuffalo/pop.
I have never previously used a framework for my GO projects. I just used the stdlib and I'm used to working with Django too.
In Django it is pretty straight forward to create/update a model and generate its migrations. It gets the current DjangoModel and generates a migration with the changes. What a surprise to me when I can't find how to do it with pop.
I already checked the documentation but I couldn't find any examples.
How do you do that?
Right now, you can only generate empty migrations and write them yourself: https://gobuffalo.io/en/docs/db/migrations#writing-migrations
There's an issue asking to implement a Django-like migrations generator (https://github.com/gobuffalo/pop/issues/184), but it's not done yet and requires a lot of work.

Can not resolve Symbol "ForSqliteHasDefaultValueSql"

I want to define a Timestamp in my EF Core Project with SQLite and wanted to use this function:
Click
I know that this function seems to be in the classic EF and maybe it is not available anymore but 3 days ago I found the right package and the extension method that I was searching. Unfortunatelly I had another problem with the code and reverted everything and now I do not find the right package anymore. It was during a hackathon during the last hours, so i really do not remember how I got it to work :/
Does anybody know which nuget package has this method? The only thing that I am referencing is Microsoft.EntityFrameworkCore.Sqlite. I allready tried the .Core and the classic EF dependencies and some random third party sqlite/ef packages, but I still can not compile this extension method :(
As you can see from the link, this method applies to EF Core versions 1.0 and 1.1.
Starting from v2.0, most of the provider specific ForAbcXyz methods have been replaced with the generic Xyz methods.
So the method you are looking for is HasDefaultValueSql. If you support multiple databases, use it inside a block enclosed with
if (Database.IsSqlite())
{
// ...
}

How to debug Entity Framework Proxies?

After a couple weeks experimenting with Entity Framework 5.0 I think I understand the basics. There's two types of proxies - lazy loading only and change tracking. I know how to enable/disable each and when to use them. However, I want to SEE these classes. I want to be able to step into them at debug time and I want to see what the logic actually does. However, since they are runtime-generated, Visual Studio can't debug them. Ideally I'd be able to pre-compile them, but right now I just want to see what they're doing.
I don't think you can actually debug proxies - at least not using Visual Studio. The types are generated on the fly. The code that generates proxies is here: http://entityframework.codeplex.com/SourceControl/changeset/view/190eef267fc7#src%2fEntityFramework%2fCore%2fObjects%2fInternal%2fEntityProxyFactory.cs (note that this is how it is done in EF6 but it has not changed much since EF5). You may also want to take a look at this blog post: http://davedewinter.com/2010/04/08/viewing-generated-proxy-code-in-the-entity-framework/ - with some hacking you will be able to save generated types to disk and use reflector to see the code.

EF migrations claims there were changes in the context while there were none

I'm using Entity Framework Migrations & Code First and recently encountered a very weird problem.
The problem was reproduced with versions 4.3.1 and 4.4.
EF thinks that the context was changed while actually it didn't.
It happens when I change the path of the solution. for example:
If my solution is located in C:\integration\something.sln the migration may work but if now I will change the path to C:\development\something.sln and re-build the solution the migration will throw an exception saying there are pending changes in the database. (Of course without any changes in the source code.
I used IL Disassembler to create a dump of the output assemblies and with BeyondCompare I saw that there are differences. I assume the data is the same but its written in different order...
How EF determines if there were changes in the context? Is it possible that the assembly check-sum comes out different and will cause EF to think that there were changes?
Any ideas are most welcome...
First, this is not a migration issue - its probably a bug in the Entity Framework's algorithm to check if there are changes in the database.
I had a class hierarchy that contained an abstract class with no properties, making that class not abstract solved the problem.
After gaining some precious debugging experience, I found several ways to solve this issue and each one raised more eyebrows than the one before which makes me very convinced that I fell on a very rare corner case. As I mentioned, I decided to solve by making a class not abstract.
I tried to reproduce the bug in a clean solution so I can send it to Microsoft but until now it didn't really work.
So... to sum things up, if you find yourself with such a problem (very frustrating one), a good tip is to look for abstract classes!

Is there a quick way to add all undefined methods?

Lately I've been using a lot of JUnit tests which have the predefined names for methods I will need to implement in my code. I find the "Create method 'x'" tool very useful but I was wondering if there was a tool that creates all the undefined methods, would anyone happen to know? This really isn't a huge problem but it would be very convenient for me to just add all of the missing methods at once as opposed to one by one.
I'm afraid that is not possible. Eclipse is able to generate all methods which you need to implement an interface, but you do not seem to have an interface here. If I understand your scenario right, you get Unit-Tests which do not compile because your class does not provide the tested methods yet.
When the class exists already, then Eclipse should suggest you to create a method with the needed signature. That is what you probably mean with "one by one".
In your case the fastest way is:
create the class
go into your unit test
jump through all non-compiling methods using command + . and create the methods using auto-suggest