FAQ Database Discussion Community


EF7: Foreign Keys are not generated when adding to Database Context

c#,linq,asp.net-mvc-6,entity-framework-7
I'm currently using Entity Framework 7.0.0-beta3 and am trying to create a many-to-many relationship between two tables. For that I'm using the syntax from The answer of this question, minus the ICollections: public class Permissions { public Guid PermissionId { get; set; } public string Name { get; set; }...

Entity Framework 7 Migration Scaffolding in Class Library with Configuration

code-first-migrations,asp.net-5,visual-studio-2015,entity-framework-7,dnx
Trying to add migrations to an EF7 Model that lives in an ASP.NET 5 class library. When running dnx . ef migration add mymigration fails with different results depending on which project I run it on. If I run it in the folder of the main project, it cannot locate...

SQLite.net Extensions loads the same entity multiple times rather than returning the same reference

entity-framework,entity-framework-7,sqlite-net-extensions
I'm using the PCL version of SQLite.Net Extensions in a Windows 10 universal app. This is my first time using it. It generally seems to be working, but it appears to be loading an entity multiple times rather than reusing a reference to the same object. According to the SQLite.Net...

Entity Framework 7 Reverse Engineering ASP.NET 5

c#,asp.net-mvc,code-first-migrations,entity-framework-7
I have been trying to migrate my database into web app model using EF7 _4. Couple things I realized is that the syntax/approach how to configure particular entities has been changed. Normally you generate POCO classes by using EF Power Tools (EF6), which generates entity types and entity map as...

Adding a sub collection of new object and my new object into the database with Entity framework

entity-framework,entity-framework-7
The method is really simple and I don't see what am I missing... public int SaveEvent(Data.Models.Event evnt) { db.Events.Add(evnt); db.SaveChanges(); return evnt.EventId; } here is the object declaration: public class Event { public int EventId { get; set; } public string Name { get; set; } public ICollection<EventTag> EventTags {...

How to work with collections

c#,entity-framework,entity-framework-7
Can anyone write mini-guide which explains how to work with collections in EF? For example I have following models: public class BlogPost { public int Id { get; set; } public string Title { get; set; } public string Content { get; set; } public DateTime DateTime { get; set;...

Entity Framework 7 group by

asp.net-5,asp.net-mvc-6,entity-framework-7
I'm trying to run the following code but when I check the SQL profiler it looks like it runs a full select on the table and then does the grouping after it returns all results from the database. Any help is appreciated. var result = _dbContext.LogEvent.GroupBy(x => x.EventLevel) .Select(g =>...

In an ASP.Net vNext site, why does a migrations-related exception appear at startup?

c#,asp.net,entity-framework-7
I have no migrations defined but I am still seeing an exception about the __MigrationHistory table at startup, after a lengthy timeout. My initialization code looks like this: public void ConfigureServices(IServiceCollection services) { services.AddMvc(); services.AddEntityFramework() .AddSqlServer() .AddDbContext<DiContext>(options => options.UseSqlServer(Configuration.Get("ConnectionString"))); } public void Configure(IApplicationBuilder app) { var loggerFactory =...

asp.net 5, indentity 3 and modular projects

asp.net,entity-framework-7,asp.net-identity-3
I'm trying to create the modular project on the asp.net 5 (vnext) on dnxcore50. I have the problems with the new Identity 3 (or either with replacing it with the custom security classes). My project contains Models subproject, DataAccess subproject and DataAccess.EntityFramework subproject. DataAccess contains only interfaces (for example, repositories...

ASP.NET vNext with EntityFramework.Core

asp.net-5,entity-framework-7
In my ASP.NET vNext project I'm using 2 dependencies from Entity Framework 7, which are : "EntityFramework.SqlServer": "7.0.0-beta1" "EntityFramework.Commands": "7.0.0-beta1" I want to use the beta2 release, and so I added a third dependency which is "EntityFramework.Core": "7.0.0-beta2". So I have : "EntityFramework.SqlServer": "7.0.0-beta2" "EntityFramework.Commands": "7.0.0-beta2" "EntityFramework.Core": "7.0.0-beta2" But Visual...

Dependancy Injected DbContext is empty after populating DbContext created with new (EF7, ASP.NET 5, vnext)

asp.net,entity-framework,dbcontext,asp.net-5,entity-framework-7
I am relatively new to EF7 and have heard that Dependency Injection of DbContexts into the Controller constructor is a good way to go about getting the DbContext for use within given Action methods. However, there are many situations where Dependency Injection is impossible (for example, accessing the Db in...

db.database.ExecuteSQLCommand equivalent in EF 7

entity-framework,asp.net-5,asp.net-mvc-6,entity-framework-7
Whats the equivalent of db.Database.ExecuteSqlCommand(Sql.ToString()); in Entity Framework 7? I saw .FromSQL() in beta 4, but haven't seen anything to the above....

Include several references on the second level

asp.net-mvc-6,entity-framework-7
Assume we have this model : public class Tiers { public List<Contact> Contacts { get; set; } } and public class Contact { public int Id { get; set; } public Tiers Tiers { get; set; } public Titre Titre { get; set; } public TypeContact TypeContact { get; set;...

Unable to use data annotations

c#,entity-framework-7
So here we are trying to get a handle on EF7 ahead of the game and I'm running into what I can only call madness. In EF6 I use annotations quite a bit and I am trying to carry that over into EF7 which according to the UnicornStore project this...

EF7 One to One relationships

c#,entity-framework-7
I'm currently working on getting a handle on the new EF7 and I am running into an odd behaviour when dealing with one to one relationships. I have the following models public class Material { [Key] [Required] [Column(TypeName = "bigint")] public long Id { get; set; } [Required] [MaxLength(128)] public...

Call stored procedure or run sql query?

c#,sql-server,entity-framework,entity-framework-7
Is it possible yet to execute a stored procedure or execute a piece of SQL in EF7? To do this in earlier EF versions we have a variety of options such as those detailed on MSDN here If not is there a plan to allow this through one of the...

Many nested AggregateExceptions

c#,async-await,entity-framework-7,aggregateexception
Working with Entity Framework 7, I made a simple mistake with some linq (used Skip and forgot to include my OrderBy clause). The exception that was thrown by this included a number of nested aggregate exceptions. The code that generates (and catches) the exception is: int[] newIds; try { newIds...

Cannot run migration on Entity Framework 7 beta4 in class library package

c#,entity-framework-7
I am unable to execute migration command in a class library package. My dnvm version is (from global.json): "sdk": { "version": "1.0.0-beta5-12021" } I'm importing this in my project JSON. "dependencies": { "EntityFramework.Commands": "7.0.0-beta4", "EntityFramework.SqlServer": "7.0.0-beta4", "Microsoft.CSharp": "4.0.0-beta-22816", "System.Collections": "4.0.10-beta-22816", "System.Linq": "4.0.0-beta-22816", "System.Threading": "4.0.10-beta-22816", "EntityFramework.Core": "7.0.0-beta4" }, "commands": { "ef":...

ASP.NET vNext MVC and Entity Framework issues

entity-framework,asp.net-5,entity-framework-7
I'm trying to create a little ASP.NET vNext WebAPI + AngularJS + Entity Framework project. But obviously, a lot changed in EF7 so I am experiencing the following issues: I changed the project.json as following: "dependencies": { "Microsoft.AspNet.Server.IIS": "1.0.0-beta1", "EntityFramework": "7.0.0-beta1", "EntityFramework.SqlServer": "7.0.0-beta1", "EntityFramework.Commands": "7.0.0-beta1", "Microsoft.AspNet.Mvc": "6.0.0-beta1", "Microsoft.AspNet.Diagnostics": "1.0.0-beta1", "Microsoft.Framework.ConfigurationModel.Json":...

Entity Framework 7 and login failed

c#,asp.net,asp.net-mvc,entity-framework-7
I'm trying to work with ef7 and asp.net mvc 6, but when i try to work with db there comes following exceptions: Cannot open database "Posts" requested by the login. The login failed. Login failed for user 'alexpc\Alexandr'. In DbContext class i use following code: protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)...

EF7 Beta 4 : AddEntityFramework dont accept argument (Configuration)

asp.net-5,entity-framework-7
I am going through this example: http://stephenwalther.com/archive/2015/01/17/asp-net-5-and-angularjs-part-4-using-entity-framework-7 and i am struggling with this code part: using Microsoft.AspNet.Builder; using Microsoft.Framework.DependencyInjection; using Microsoft.Data.Entity; using creaservo.com.Models; using Microsoft.Framework.ConfigurationModel; using Microsoft.AspNet.Hosting; namespace creaservo.com { public class Startup { public Startup(IHostingEnvironment env) { // Setup configuration sources. Configuration = new...

EntityFramework 7 database already exists error on migrations

asp.net-5,entity-framework-7
ASP.NET 5 project, Entity Framework 7. Using all the default stuff that comes with the ASP.NET 5 web template for creating the Identity Context. When I start up the app and first try to hit the context (register or log in), there is an error on Database.AsRelational().ApplyMigrations() that the database...

Can these models be represented in EF7?

c#,entity-framework-7
I'm trying to use some classes from another assembly in my own project as entities that I can persist using EF7, rather than writing a series of very similar classes that are more database-friendly. Simplified versions look like this: interface IMediaFile { string Uri { get; } string Title {...