ef-code-first

Has column type of complex type in ef core 2.0

做~自己de王妃 提交于 2019-12-12 18:34:52
问题 I want to change column type of property using fluent api, but i have an error The expression 'x => x.NestedProp.Prop1' is not a valid property expression. The expression should represent a property access: 't => t.MyProperty'. please, i dont want to use DataAnnotations Here is my code (Classes): public class Class1 { public int Id { get; set; } public NestedProp NestedProp { get; set; } = new NestedProp(); } public class NestedProp { public decimal Prop1 { get; set; } } And OnModelCreating:

Error generating ScaffoldingConnectionFactory

早过忘川 提交于 2019-12-12 18:04:10
问题 I have a simple class called Applicant. I'm trying to add a template controller using the Entity Framework with Applicant as my model class, and a new data context. Every time I try to create the controller, I get an error dialog that says "Unable to retrieve metadata for 'MyNameSpace.Models.Applicant'. There was an error generating 'ScaffoldingConnectionFactory'. Try rebuilding your project." Rebuilding does nothing. Here is my model class: using System; using System.Collections.Generic;

Generate repositories from EF Code First with created DbContext model classes

不问归期 提交于 2019-12-12 17:41:17
问题 I'm starting a new project and want to use EF Code First pattern but I also want to use the repository pattern. I have been looking for a way to generate the repositories from the dbcontext models but all answers I've seen so far are for generating repositories from .edmx or DB. I don't want to create an .edmx. The steps I want to do is this: 1. Write models 2. Generate repositories using t4 templates 3. Write app code from models and repos 4. Run Add-Migration to add migration code 5. Run

Entity Framework Code First associations/FK issues and assumptions/defaults

ε祈祈猫儿з 提交于 2019-12-12 16:13:20
问题 I am very confused by the way Entity Framework is able to pick up on relationships between entities. I have a few questions on this. In a simple test application, I have a table of people, and a table of notes, and a table of picture assets. There are many pictures, each is owned by a person (a person can own more than one). There are many notes, each is owned by a person (a person can own more than one). and finally a person has a logo which is a picture. . public class Person { public int

Entity Framework 5, Code First, Full Text Search but IQueryable via CreateQuery?

旧巷老猫 提交于 2019-12-12 16:01:49
问题 I am using .NET 4.5 and EF 5 with Code First approach and now I need to implement Full Text Search. I have already read a lot about it and so far my conclusions are: Stored procedures nor Table Value Functions can not be mapped with Code First. Still I can call them using dynamic sql dbContext.Database.SqlQuery<Movie>(Sql, parameters) But this returns IEnumerable and I want IQueryable so that I can do more filtering before fetching the data from db server. I know I can send those parameters

EF Core DbUpdateConcurrencyException does not work as expected

纵饮孤独 提交于 2019-12-12 15:35:39
问题 I have the following code that I am trying to update ClientAccount using ef core but they Concurrency Check fails: public class ClientAccount { [Key] [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public long Id { get; set; } [Required] [ConcurrencyCheck] public double Balance { get; set; } [Required] public DateTime DateTimeCreated { get; set; } [Required] public DateTime DateTimeUpdated { get; set; } } public class ClientRepository { private readonly MyContext context; public

One-to-one relationsip with optional dependent end using default conventions

吃可爱长大的小学妹 提交于 2019-12-12 14:05:05
问题 I'd like to have a principal entity ( Person ) with optional dependent entity ( Car ) mapped using the default conventions in Entity Framework code-first model. One solution is described in this answer, which uses the fluent API on modelBuilder to map to the key. Is it possible to do this using only the default EF conventions? The following code will throw a Unable to determine the principal end of an association between the types Person and Car. invalid operation exception. public

Entity Framework 5 - Invalid column name - Reverse Engineer Code First

回眸只為那壹抹淺笑 提交于 2019-12-12 13:24:24
问题 Using Entity Framework 5 , Visual Studio 2010 with the Entity Framework Power Tools (Beta 2) extension. Here is my database table structure: I used the Reverse Engineer Code First function of the aforementioned extension, which generated the POCO classes and some 'mapping' files (not sure if that's the formal parlance) and a single DbContext-derived class. Other than the change I describe next, all of these generated classes are as-generated by the power tool. In the Category.cs file, I added

why when i want use EF Power tools for view my model i get error?

天涯浪子 提交于 2019-12-12 12:51:40
问题 Im using EF Code first and i generate my model by "EF 4.x DbContext Fluent Generator for c#" extension in vs2010. but when i want to view my Entity model via EF Power tools i get this error:"Sequence Contains no matching element". is there any idea? 回答1: It's a bit too late and not sure if this would help but for others and historic reasons... I had the same issue (with Beta 3 - and .NET 4/2010/EF5 etc.) - the solution was relatively simple. I just moved out the project from the 'solution

System.data.SQLite entity framework code first programmatic providername specification

穿精又带淫゛_ 提交于 2019-12-12 12:29:20
问题 I've spent a while on this now and have only found a workaround solution that I'd rather not do... I have a context as shown below. Is there a programmatic way to specify the database to connect to via the constructor, and get it to use the System.Data.SQLite entity framework provider to connect to a SQLite database? This is working via the app.config (with a connectionstring called "Context"), but not via any programmatic way I can find of supplying it. I have tried using an entity