ef-code-first

Code-First Add-Migration keeps adding the same column

一笑奈何 提交于 2019-12-22 04:49:09
问题 My model contains, among other things, two properties that were added to the model class after its initial creation and migration. public sealed class SomeModel { ... other properties, which are fine. public int PropertyOne { get; set; } public int PropertyTwo { get; set; } } My most recent migration contains: public override void Up() { ... other table being created. AddColumn("dbo.SomeModel", "PropertyOne", c => c.Int(nullable: false)); AddColumn("dbo.SomeModel", "PropertyTwo", c => c.Int

The navigation property 'FootballGame' was not found on the dependent type 'Bd.Domain.Entities.FootballGame'

混江龙づ霸主 提交于 2019-12-22 04:46:37
问题 I am creating my first asp.net mvc3 application. I'm using code first methodology. I have the following models: public class FootballGame { [Key] public Guid id_FootballGame { get; set; } [ForeignKey("FootballGame")] public Guid? FK_id_FootballGame { get; set; } public virtual FootballGame PreviousFootballGame { get; set; } [ForeignKey("FootballTeam")] public Guid id_FootballTeam_owner { get; set; } public virtual FootballTeam FootballTeamOwner { get; set; } [ForeignKey("FootballTeam")]

EF Code First - Fluent API (WithRequiredDependent and WithRequiredPrincipal)

巧了我就是萌 提交于 2019-12-22 04:33:21
问题 I have the following class: public class User { public Guid Id { get; set; } public string Name { get; set; } public Couple Couple { get; set; } } public class Couple { public Guid Id { get; set; } public User Groom { get; set; } public User Bride { get; set; } } Important points: Bride and Groom properties are required One-to-one relationship In the User class, it is Couple required DbContext in OnModelCreating modelBuilder.Entity<User>().HasRequired(u => u.Couple).WithRequiredPrincipal();

Entity Framewok Code First “ADO.NET provider not found” with local SQL Server CE DLL's

半腔热情 提交于 2019-12-22 04:27:08
问题 I am writing a C# application which uses SQL Server CE 4.0 files, which are accessed through the Entity Framework 6.0 via code-first. (The application needs to be able to use local dll's for the SQL Server CE connection i.e. the application needs to be XCOPY deployable). The application runs fine on my development machine, but on other machines (e.g. VMs with just Win7 and .NET 4.0), I get an ArgumentException : The ADO.NET provider with invariant name 'System.Data.SqlServerCe.4.0' is either

Where can I find the console or debug output from code executed in the package manager window?

你。 提交于 2019-12-22 01:47:12
问题 I'm using EntityFramework code first with migrations. From the package manager console, I'm running "update-database". This executes Configuration.Seed(context) which I have overridden. protected override void Seed(WebContext context) { Console.WriteLine("Console Test"); Debug.WriteLine("Debug Test"); Trace.WriteLine("Trace Test"); } Where can I find that output? Better yet, How do I output back to the package manager window? Thx, Dan 回答1: Where can I find that output? Sorry, but the quick

Conditional mapping with graphdiff

一笑奈何 提交于 2019-12-22 01:23:51
问题 I have following entities in my DbContext : public class A { public A() { Bs = new List<B>(); } public ICollection<B> Bs { set; get; } } Sometimes I Want to update a graph: var a = dbContext.As .AsNoTracking() .Include(x=>x.Bs) .firstOrDefault(); var c = new C(); a.Bs.Add(c); var d = new D(); var e1 = new E(); var e2 = new E(); d.Es.Add(e1); //<-- added new E d.Es.Add(e2); //<-- added new E a.Bs.Add(d); I want to update a with its Bs (update C , D , E too) using graphdiff : dbContext

The declared type of navigation property XYZ is not compatible with the result of the specified navigation

浪子不回头ぞ 提交于 2019-12-22 01:07:23
问题 Hi There I have the following Model Template (Id,Name) UserBody (Id, name) EmployeeBody (Id, Name) I then Have a template mappers where i associate a template with one of many users and employess. TemplatesMaps (id, TemplateId, UserId, EmployeeId) userid and employeeId are nullable I need a TemplatesMaps to consist of 1 templateid mapping to many Userbody.id 's and many EmployeeBody.Id's Example Id TemplateId UserBodyId, EmployeeBodyId 1 1 1 Null 2 1 Null Null 3 2 4 Null 4 2 Null 5 MY Code is

Entity Framework 4.1 simple dynamic expression for object.property = value

不打扰是莪最后的温柔 提交于 2019-12-22 00:46:18
问题 I know there is a way to use Expressions and Lambdas to accomplish this but I having a hard time piecing it all together. All I need is a method that will dynamically query an Entity Framework DBSet object to find the row where the propery with the given name matches the value. My context: public class MyContext : DbContext { public IDbSet<Account> Accoounts{ get { return Set<Account>(); } } } The method that I'm looking to write: public T Get<T>(string property, object value) : where T is

Setting up a Entity Framework Code First Database on SQL Server 2008

两盒软妹~` 提交于 2019-12-21 23:12:02
问题 I successfully created my first Entity Framework Code first project using SQL Server CE. The database tables were created automatically and all was well. I then changed my connection string to point to a SQL Server database I'd created and expected it to autogenerate the tables. It didn't and instead complained about the tables not existing. After some reading I found that I needed to add an initializer to my App_Start method. I tried: // Method 1 Database.SetInitializer(new

EntityFramework Npgsql DbConfiguration doesn't work

五迷三道 提交于 2019-12-21 22:04:01
问题 Im trying to configure EntityFramework with Npgsql with code first. EntityFramework 6.1.3 Npgsql 3.0.5 Now, i want to set a custom configuration by a class, let's see: public class DbConfig : DbConfiguration { public DbConfig() { SetProviderFactory("Npgsql", Npgsql.NpgsqlFactory.Instance); SetProviderServices("Npgsql", provider: NpgsqlServices.Instance); SetDefaultConnectionFactory(new NpgsqlConnectionFactory()); } } and my context class: [DbConfigurationType(typeof(DbConfig))] public class