I do not get context DeleteOnSubmit!! All other functions like Add, Count, etc… work fine! Due to this, I cannot delete the record.
Error 1 'System.Data.Entity.DbSet<mvc2db.Company_Dext>' does not contain a
definition for 'DeleteOnSubmit' and no extension method 'DeleteOnSubmit' accepting
a first argument of type 'System.Data.Entity.DbSet<mvc2db.Company_Dext>' could be
found (are you missing a using directive or an assembly reference?)
I am using Visual Studio 2012 Premium edition
thanks
In Entity Framework 5, there is no DeleteOnsubmit instead there is .Remove(record entity).
Related
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.
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.
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
Error when using a DbContextBaseClass that does not implement a constructor,is there any documentation,Example or Demo on how to use DbContextBaseClass in the template setting to make ASP.NET Identity works ?
i used the guide in the comment:
DbContextBaseClass = "DbContext"; // Specify what the base class is for your DbContext. For ASP.NET Identity use "IdentityDbContext<ApplicationUser>"
but i always end up with two a compile errors :
1- The type or namespace name 'IdentityDbContext' could not be found
(are you missing a using directive or an assembly reference?)
2- The type or namespace name 'ApplicationUser' could not be found
(are you missing a using directive or an assembly reference?)
Apparently someone else is having the same issue :
Link Here
As the ASP.NET identity already includes all the entity framework code within your project, there is no need to reverse engineer it.
I would instead use the Reverse POCO generator to reverse engineer all your own tables, and add a filter to exclude the ASP.NET identity tables alone.
TableFilterExclude = new Regex("^__MigrationHistory$|^AspNetRoles$|^AspNetUserClaims$|^AspNetUserLogins$|^AspNetUserRoles$|^AspNetUsers$");
I have using entity framework 6 in a project that is net 4.0, and when I instaled the nuget package, the project adds the reference to EntityFramework.dll and EntityFrameWork.SqlServer.dll.
However, I want to capture the exception EntityCommandExecutionException, but there is not avaliable in neither of the both dlls.
I know that I can add a reference to System.Data.Entity, but I don't konw if this a good solution, because when I try to use the enum EntityState there are a conflict because the are one in the System.Data.Entity and other in EntityFramework.dll.
So the quiestion is if it is a good idea to use the System.Data.Entity library with EF 6. And if it is a bad idea, which is the equivalent exception of EntityCommandExecutionException in EF 6?
Thanks.
EF6 does not use System.Data.Entity.dll so adding a reference to this assembly won't help since EF6 will throw its own EntityCommandExecutionException. Actually adding a reference to an EF6 project will create even more confusion since the two are not designed to work together even though the type names tend to be called the same (EF6 was build by merging System.Data.Entity.dll and EntityFramework.dll code bases but is not binary compatible with EF5). In your app you need add
using System.Data.Entity.Core;
since this is where the EntityCommandExecutionException type lives in EF6.