ef-model-builder

Storing custom class property like String via OnModelCreating of DBContext .Net Core

孤人 提交于 2021-02-11 12:22:22
问题 I have two classes in .Net Core The class Owner namespace CustomStoreDatabase.Models { public class Owner { public string OwnerId { get; set; } public DateTime MinDateTime { get; set; } public DateTime MaxDateTime { get; set; } public TimeSpan Interval { get; set; }//store like a double public Ownership Ownership { get; set; } //store like a JSON String in the db } } And the class Ownership namespace CustomStoreDatabase.Models { public class Ownership { public string OwnershipId { get; set; }

Enitity Framework Each property name in a type must be unique

孤街浪徒 提交于 2019-12-24 19:04:44
问题 I have the following entities defined and the relationship mapping also. However, while saving i get the error Name: Each property name in a type must be unique. Property name 'ResponseId' is already defined. in EF 6 System.Data.Entity.ModelConfiguration.ModelValidationException I am struck with this for 2 days and not sure, what is the issue in my class. If I remove, ResponseId in ResponseOffer, it is working fine. However, I need to set this value to save it in the database and its FK

EF Core 2.0 provider specific model configuration

孤街醉人 提交于 2019-12-24 01:53:58
问题 I am trying to upgrade an EF Core 1.x project to 2.0. In 1.x I was taking advantage of provider-specific extension methods (e.g. ForSqlServerHasDefaultValueSql / ForSqliteHasDefaultValueSql or ForSqlServerHasColumnType ) but these seem to have been removed in 2.0. Since each provider has its own flavor of SQL and capabilities, I need to be able to use slightly different setups or SQL strings per provider in OnModelCreating . For example to set a default value I might have: modelBuilder<Foo>(b

EF Core: Using ID as Primary key and foreign key at same time

谁说胖子不能爱 提交于 2019-12-23 00:26:36
问题 I have two entites, Prospect and person, what I'm trying to do is use Prospect.ID as primary key on ProspectTable and as foreignkey of PersonID, my ideia is use the same ID for both entities without the need of a PersonID on my Prospect entity. When the prospect is being saved on database, it tries to save a PersonID even I not have this property on my Prospect entity, I would like to know if ef core supports this kind of relationship. Here's what I got on my model builder. modelBuilder

Persistance datalayer in EF core ,dynamic EF. Separate EF from models

泪湿孤枕 提交于 2019-12-19 04:57:45
问题 I want to separate EF layer from my model . I need a EF Builder to send my model to it like this(I found this code for mongodb but i need for EF core) : builder.AddMongo(); builder.AddMongoRepository<Cart>("Carts"); builder.AddMongoRepository<Customer>("Customers"); builder.AddMongoRepository<Product>("Products"); The above code is inside startup file . I pass the parameters from applicationsetting.json file as you can see : "mongo": { "connectionString": "mongodb://localhost:27017",

How to parse password in varbinary from database to IdentityUser string in Web Api Authentication

天大地大妈咪最大 提交于 2019-12-11 14:43:14
问题 I have in my database a column named Password of type Varbinary(150) . When I want to consult that database in the web api, for example: var dbCon = ApplicationDbContext.Create(connectionStringUsers.ToString()); var users = dbCon.Users; var list = users.ToList(); In the last line I have this error: The 'PasswordHash' property on 'IdentityUser'4' could not be set to a 'System.Byte[]' value. You must set this property to a non-null value of type 'System.String'. It know that if I change my

EF Core: Using ID as Primary key and foreign key at same time

点点圈 提交于 2019-12-06 05:36:10
I have two entites, Prospect and person, what I'm trying to do is use Prospect.ID as primary key on ProspectTable and as foreignkey of PersonID, my ideia is use the same ID for both entities without the need of a PersonID on my Prospect entity. When the prospect is being saved on database, it tries to save a PersonID even I not have this property on my Prospect entity, I would like to know if ef core supports this kind of relationship. Here's what I got on my model builder. modelBuilder.Entity<ProspectDto>(builder => { builder.ToTable("Prospects"); builder.HasKey(prospect => prospect.ID); });

Resolving 'No key Defined' errors while using OnModelCreating with ApplicationDbContext?

瘦欲@ 提交于 2019-12-01 04:44:36
I've been trying to create navigation properties for my collection types and I found this example of how one person accomplished it using OnModelCreating. I gave it a try in my MVC 5 application and I recieved this error when trying to update my database: One or more validation errors were detected during model generation: BlogEngine.Models.IdentityUserLogin: : EntityType 'IdentityUserLogin' has no key defined. Define the key for this EntityType. BlogEngine.Models.IdentityUserRole: : EntityType 'IdentityUserRole' has no key defined. Define the key for this EntityType. IdentityUserLogins:

Resolving 'No key Defined' errors while using OnModelCreating with ApplicationDbContext?

99封情书 提交于 2019-12-01 02:39:56
问题 I've been trying to create navigation properties for my collection types and I found this example of how one person accomplished it using OnModelCreating. I gave it a try in my MVC 5 application and I recieved this error when trying to update my database: One or more validation errors were detected during model generation: BlogEngine.Models.IdentityUserLogin: : EntityType 'IdentityUserLogin' has no key defined. Define the key for this EntityType. BlogEngine.Models.IdentityUserRole: :

How to disable model caching in Entity Framework 6 (Code First approach)

纵然是瞬间 提交于 2019-11-29 11:56:01
问题 Following MSDN documentation we can read: The model for that context is then cached and is for all further instances of the context in the app domain. This caching can be disabled by setting the ModelCaching property on the given ModelBuidler , but note that this can seriously degrade performance. The problem is the model builder does not contain any property named ModelCaching . How it is possible to disable the model caching (e.g. for changing model configuration in a run-time)? 回答1: I have