Entity Framework 7 Errors from Key, Collection, Reference definitions missing in ASP.NET Beta 8 - entity-framework

Problem
I am having trouble with upgrading my beta7 application to beta8. I had problems with over 50 errors, but now have gotten it down just to EF7. It was recommended by stack overflow friends and users that I ask this question specifically.
Entity Framework Error
Error CS1061 'EntityTypeBuilder<Unit>' does not contain a definition for 'Collection' and no extension method 'Collection' accepting a first argument of type 'EntityTypeBuilder<Unit>' could be found (are you missing a using directive or an assembly reference?) SampleProject.DNX 4.5.1
I get the same error for Reference as well.
I have the following code in my OnModelCreating(ModelBuilder builder) method in my DbContext.cs file.
builder.Entity<Unit>(entity =>
{
entity.HasKey(unit => unit.UnitId);
entity.Collection(unit => unit.UnitBins).InverseReference(bin => bin.BinUnit)
.ForeignKey(bin => bin.UnitId).Required(true);
entity.Reference(u => u.RefUnitType).InverseReference().ForeignKey<Unit> (u => u.RefUnitTypeId).Required();
});
The problem is that EntityBuilder does not seem to have definitions for Collection and Reference. This is about the second or third time this kind of logic has been refactored in EF it feels like and so I am very confused as to how to rewrite my logic above.
Attempts:
I tried the following things:
I tried using intellisense in VS15, but nothing similar was found
I have searched the EF7 issues GitHub page, but didn't see anything
I also tried dnu restore just to be sure the upgrade didn't do something strange with my project.json lock.
Using entity.HasKey() instead of entity.Key(), but have not found other methods comparable to the others?
Now that beta8 is feature complete, I may rewrite significant portions of my project. However, for now I need to resolve these errors so that I can compile the project again. Any help, assistance, and advice rendered would be greatly appreciated.

Collection => HasMany
Reference => HasOne
InverseReference => WithOne

Related

DNN deprecated methods on upgrade

I'm trying to upgrade my old DNN website to DNN version 9.8.0. The problem is that I have one custom module installed and it is using deprecated methods that I'm resolving using the table of deprecated methods and I ran on one issue that I don't really understand what to do with it:
retRole = DotNetNuke.Security.Roles.RoleProvider.Instance().GetRole(module.PortalId, roleid);
Error is: 'DotNetNuke.Security.Roles.RoleProvider' does not contain a definition for 'GetRole' and no extension method 'GetRole' accepting a first argument of type 'DotNetNuke.Security.Roles.RoleProvider' could be found (are you missing a using directive or an assembly reference?)
In the table of deprecated method, for public virtual RoleInfo GetRole(int portalId, int roleId) it says: Deprecated in DotNetNuke 6.2. Roles are cached in the business layer
Does anyone knows what it means and how to resolve this?
Instead of using the RoleProvider, I would use the RoleController:
retRole = DotNetNuke.Security.Roles.RoleController.Instance().GetRoleById(module.PortalId, roleid);
In DNN9.8, RoleProvider doesn't have the method GetRole anymore.

EF Core Second level ThenInclude missworks

Assume having these models first:
Method that has one OriginalCode
OriginalCode that has many Mutants
Mutant that has many ParseSubTrees
Now when querying on Method I want the other being loaded. So I have the following:
Method targetMethod = dBContext.Methods
.Include(me => me.OriginalCode)
.ThenInclude(oc => oc.Mutants)
.FirstOrDefault(me => me.Id == id);
and the next step is to include additionally the ParseSubTree. But the thing is that I can't access it. See the following Image:
the problem is "mu is a list instead of being an object reference"!
Where is my mistake!
TG.
This is a known Intellisense issue with the ThenInclude overload for collection type navigation properties, tracked by the Completion missing members of lambda parameter in fault tolerance case #8237 Roslyn GitHub issue.
Until it gets fixed, simply type the name of the property and it will compile successfully and work as expected.
.ThenInclude(mu => mu.ParseSubTrees)
Update: Now it's even specifically mentioned in the Including multiple levels
section of the EF Core documentation:
Note
Current versions of Visual Studio offer incorrect code completion options and can cause correct expressions to be flagged with syntax errors when using the ThenInclude method after a collection navigation property. This is a symptom of an IntelliSense bug tracked at https://github.com/dotnet/roslyn/issues/8237. It is safe to ignore these spurious syntax errors as long as the code is correct and can be compiled successfully.
In my case there was a conflict between the namespaces System.Data.Entity and Microsoft.EntityFrameworkCore. Just delete the first using line.

EF - Eager include grandchildren not working, does not contain definition for 'Select'

I am working in VS 2015 solution with an MVC 5 project and a code library project using EF 6.1. I have redone the entire project from a previous version in VS 2013 hoping it would resolve this problem, but no luck. I am just trying to eager load a child with grandchildren. I tried this:
Test t = db.Tests
.Include("TestsRemoteOBD")
.Include("TestsRemoteOBD.TestsRemoteOBDDtcs")
.FirstOrDefault();
and this:
Test t = db.Tests
.Include(i=>i.TestsRemoteOBD)
.Include(i=>i.TestsRemoteOBD.Select(s=>s.TestsRemoteOBDDtcs))
.FirstOrDefault();
Include using the string works for the child, but not the grandchildren. And with the 2nd query, I'm getting this error:
'TestsRemoteOBD' does not contain a definition for 'Select' and no extension method 'Select' accepting a first argument of type 'TestsRemoteOBD' could be found (are you missing a using directive or an assembly reference?)
I've seen the same question resolved by adding "using System.Data.Entity;", but I had done that a long time ago. No help. What else could I be missing?
Thanks!
Thanks so much, to all those who commented. I would have been banging my head for another day, at least. The way I had written the second statement would have worked fine if the parent [Tests] had a 1-to-many relationship with [TestRemoteOBD], but since the latter was not a collection, there was no 'Select' defined. I have not tested, but I believe it should be something like:
Test t = db.Tests
.Include(i=>i.TestsRemoteOBD)
.Include(i=>i.TestsRemoteOBD.TestsRemoteOBDDtcs)
.FirstOrDefault();
Bump. Found this and thought I'd throw in my own research.
Microsoft's
Documentation
states: To include a reference and then a reference one level down: query.Include(e => e.Level1Reference.Level2Reference)
-- but this doesn't seem to work under even the simplest use case. Executing the query with a .ToList() does not actually include anything. Smells like an obvious bug to me!
I can see 2 workarounds.
First, as Ben here suggests, you can manually iterate over the entities to force EF to load them.
Second, if scoping permits, you can forget the 'using' block and keep a more permanent instance of the dbcontext as a class member so that it's still available, not disposed (System.ObjectDisposedException), when the members are accessed.

Doctrine 2.1 abstract entity, validation using annotations

My name is Denis and I really need your help or advice or anything :)
I am developing my project in Zend Framework 1.11 and am using Doctrine 2.1.
I have successfully integrated Doctrine in my ZF project and everything works. I also integrated Gedmo extensions and some my custom extensions.
The problem is with validation. I want to have validation of doctrine entities by using annotations. Because I sometimes need to validate my entities sometimes don't, I want that sort of validation, for example:
$user = new Entity\User; $user->setName('user'); $user->validate();
I don't want to change doctrine generated entities at all, so I won't change setters or use doctrine events for this.#HasLifecycleCallbacks.
I run into example at http://www.spiffyjr.me/2011/07/15/more-doctrine-2-and-zend-framework-integration-goodies/.
I downloaded code but didn't managed to put it in work. I followed instructions from that page, made my entities extend AbstractEntity, but when try to use for example isValid() i recieve following error:
[Semantical Error] The annotation "#Column" in property Bild\Entity\TestTest::$id was never imported. Did you maybe forget to add a "use" statement for this annotation?
I use doctrine annotations without #ORM\, just #, (for example #Column, not #ORM\Column). I even tried to add ORM but no luck it continues to throw errors.
I can recieve metadata for my entity, get field mappings and associating mappings, but when I try to getPropertyAnnotation
// validator annotations
$vAnnotations = self::_getPropertyAnnotation($property, self::ZENDVALIDATION);
var_dump($vAnnotations);die;
I recieve mentioned semantic error.
I tracked the errors down to Doctrine\Common\Annotations\AnnotationReader::getPropertyAnnotations($property); not returning annotations but throwing errors.
What do you think it can be?
It seems like I am not doing something properly but can't figure out what.
So, I need to make abstract entity, make my entities extend it, and make functions to validate my entities by using annotations.
So please, help me with this, if you can. I really need for my project but couldn't find a solution.
Thanks in advance.
Best regards.
The problem is caused by the configuration of the annotation reader. I went through the same problems while integrating the Symfony2 validator service for my Doctrine2 models in ZF1, more on the blog post here http://ssmusoke.wordpress.com/2012/03/04/doctrine-2-day-2-model-validation-using-symfony-validator-service-in-zend-framework/

What happened to the Rx Switch() operator?

I am working my way through the Hands-On-Labs for reactive extensions (Rx HOL .NET.pdf) which I downloaded from the data developer center (here) a few days ago.
I added these references to my project, using NuGet:
System.Reactive 1.0.10621.0
System.Reactive.Windows.Forms 1.0.10621.0
I'm almost done with the labs, but I've hit a snag trying to implement the .Switch() example, Visual Studio can't locate the extension method:
'System.IObservable'
does not contain a definition for
'Switch' and no extension method
'Switch' accepting a first argument of
type
'System.IObservable'
could be found (are you missing a
using directive or an assembly
reference?)
Now I know this Hands On Labs document is out of date, because certain things have been renamed (FromEvent became FromEventPattern) and certain things were removed (RemoveTimeStamp) and this document does not reflect that. For the life of me I cannot guess what they renamed Switch to be, or figure out what assembly they might have moved it to, or find a comprehensive list of release notes that indicate it was removed.
Anyone know where I can find Switch and what it's current name is?
The Switch extension method doesn't extend IObservable<T> - it extends IObservable<IObservable<T>>. The full signature is:
IObservable<TSource> Switch<TSource>(this IObservable<IObservable<TSource>> sources)
Try typing Observable.Empty<IObservable<object>>(). and see if Switch appears then.
If not, check your using namespace declarations.