ef-code-first

Schema specified is not valid. Errors: The relationship 'Product_CreatedByUser' was not loaded because the type 'User' is not available

大憨熊 提交于 2019-12-12 04:57:29
问题 I have following code first models and I try to initialized database it giving me error mention below. One user can have multiple products so there is one to many relationship between user and product. Schema specified is not valid. Errors: The relationship 'Models.Product_CreatedByUser' was not loaded because the type 'User' is not available. I am using code first approach, can any one help me with this. User: public class User { public long UserId { get; set; } public string FirstName { get

How to avoid recreate an existing database using automatic Code First Migration

本秂侑毒 提交于 2019-12-12 04:56:30
问题 I am using EF6, and having an issue with database automatic migration. The database exists, and there is no schema nor data changes in the db. But for some strange reason, the application seems to trying to re-create an existing table in the db on machine reboot. And therefore cause errors. My questions are: Why there will be automatic db migration when there is no db schema change? What triggered it? How to fix it. I use Include method to load entities like this, and the error occurs when I

EF Code First - Property of type Type

雨燕双飞 提交于 2019-12-12 03:56:07
问题 I have an object that has a property of type Type: public ScheduledJob { public int ID { get; set; } public Type JobType { get; set; } public string JobParameters { get; set; } } When I generate the code-first migrations, I get the following error: System.ArgumentNullException: Value cannot be null. Parameter name: key at System.Collections.Generic.Dictionary`2.FindEntry(TKey key) at System.Collections.Generic.Dictionary`2.TryGetValue(TKey key, TValue& value) at System.Data.Entity

insert statement affected an unexpected number of rows (0)

独自空忆成欢 提交于 2019-12-12 03:45:52
问题 I'm trying to insert a record using Entity Framework Code First. When trying to save the record I'm Keep getting the following error. Store update, insert, or delete statement affected an unexpected number of rows (0). Entities may have been modified or deleted since entities were loaded. Refresh ObjectStateManager entries. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where

How to define an MVC database structure using the same sub-table in different super-tables

梦想与她 提交于 2019-12-12 03:44:38
问题 I am making an hours calendar using MVC's Code First approach. This is the data-structure from the bottom-up: All classes contain table element ID's. A DaySpec contains opening and closing times for a day. A WeekSpec contains, among trivial Booleans, an array of DaySpecs. An ExceptionHoursSet, which defines hours that are exceptions to a general hours pattern, contains an integer RepCount and an object HoursSet; RepCount specifying how many times the exception is repeated, and the HoursSet

Bind WPF DataGrid to LINQ Query (Entity Framework)

↘锁芯ラ 提交于 2019-12-12 03:35:26
问题 This must be very simple, but I seem to be missing something. I've searched around for a few hours without coming across anything that can resolve my problem. The issue is that although I can assign my LINQ query to a WPF DataGrid, when I try to edit one of the DataGrid's values I get the following error: System.InvalidOperationException was unhandled Message='EditItem' is not allowed for this view. Source=PresentationFramework StackTrace: at System.Windows.Controls.ItemCollection.System

EntityFramework naming conventions for DDD ValueObjects

徘徊边缘 提交于 2019-12-12 03:25:22
问题 I use Domain Driven Design Pattern in my project. I have some ValueObjects like PersianDate that has a long type property. the name of ValueObject property in database be CreatedOn_PersianDate but I want its name be CreatedOn. I can change this property directly but how can i do it by conventions ? (FixOValueObjectAttributeConvention) public class PersianDate : ValueObject<PersianDate> { public long Value {get; set;} } public class Account : Entity { public int Id {get; set;} public

Entity Framework 4.2 code first in a class library ignoring my connection string

亡梦爱人 提交于 2019-12-12 03:17:57
问题 I'm building a class library for an application (exitgames photon) and it doesn't have a web.config or an app.config . Therefore I am setting the connection string against the context like this: db.Database.Connection.ConnectionString = "Data Source=machinename\\SqlExpress;Initial Catalog=AwesomeDB;Integrated Security=True"; The context (db) then ignores the connection string and uses the default one as if I didn't specify it (based on the namespace and context name etc). Anyone know how to

How do I configure a navigation property to the same table in Entity Framework?

青春壹個敷衍的年華 提交于 2019-12-12 03:17:04
问题 How do I configure Entity Framework using fluent configuration to behave the same way that I would do this with attributes: public class Product { public int? ParentId { get; set; } [ForeignKey("ParentId")] public virtual Product Parent { get; set; } } 回答1: Supposing that you want to create a self referencing entity, I assume that you have a Product class like this: public class Product { public int Id { get; set; } public int? ParentId { get; set; } public virtual Product Parent { get; set;

Complicated relationships vs simple tables Entity Framework CodeFirst

感情迁移 提交于 2019-12-12 02:49:39
问题 Database design question :) Is it smarter to make a lot of interconnected tables (normalize) or is it smarter to duplicate data so queries are simpler? Here is my situation: public class TransferRequest { [Key] public int TransferRequestId { get; set; } public int By { get; set; } public int? For { get; set; } public int PersonId { get; set; } public virtual Person Person { get; set; } [ForeignKey("Transfer")] public int? ExistingTransferId { get; set; } public virtual Transfer