code-first

Where the CREATE DATABASE statement is generated in Entity Framework Code First with Migrations?

只愿长相守 提交于 2019-12-13 07:20:21
问题 I need to configure the database created by Entity Framework Code First MigrateDatabaseToLatestVersion class. Is it possible to influence the database files parameters like size or maxsize? What interests me in particular, is there a way to add database files? I assume I need to find the moment where the Entity Framework generates the CREATE DATABASE statement and influence it a bit. As far as I understand, the SqlServerMigrationSqlGenerator class is too late because the database already

ASP.NET Identity Custom with Group-based Roles

别等时光非礼了梦想. 提交于 2019-12-13 05:03:07
问题 Perhaps I've misunderstood the concept of Roles in ASP.NET Identity and the database model, but I'm struggling to wrap my head around how to implement the following scenario: With ASP.NET Identity, it seems a User has permissions globally based on a Role, as opposed to permissions on a more granular level. I'm trying to implement a DB Schema in EF6 with Code-First where a User can be a member of several Groups. Instead of having a global Role however, I want the User to have one role in one

Multiplicity constraint violated. The role Child_Parent_Target of the relationship Child_Parent has multiplicity 1 or 0..1

眉间皱痕 提交于 2019-12-13 04:42:49
问题 I did a lot of research but haven't found any answer that matches my problem. I even tried to use the The relationship could not be changed because one or more of the foreign-key properties is non-nullable example. No success. I'm working with Entity Framework 6 Code First (Fluent API), POCO Classes. I have a class called Parent and a class called Child One Parent can have one or more Childs (one to many relationship) So, in my ParentMapping class I did: HasMany(p => p.Childs).WithRequired(p

entity framework 4, code-only, relationships

寵の児 提交于 2019-12-13 03:39:30
问题 I can't figure out how to solve the following problem. What i need it a relationship from one base class to another, so that every derived class has a relationship with the same table, called 'Item' in my example. Since this is just an example it doesn't reflect my program. In the real program the relationship with class Item is in a different namespace. Therefore it can't be in the derived class. The error: A key is registered for the derived type 'WebApplication1.Client'. Keys must be

How to use Stored Procedure in asp.net core with boilerplate architecture?

拥有回忆 提交于 2019-12-13 02:47:58
问题 I am using asp.net core application with abp(Asp.net BoilerPlate) framework. I want to use stored procedure to get the data and also to implement CRUD operations in this code first architecture. What will be best way to do so? Thanks in advance 回答1: Here is an example that sends a parameter to a stored procedure to delete a user: public async Task DeleteUser(EntityDto input) { await Context.Database.ExecuteSqlCommandAsync( "EXEC DeleteUserById @id", default(CancellationToken), new

C# CodeFirst Lazy Loading with MVVM

偶尔善良 提交于 2019-12-13 00:53:05
问题 I have a moderate-sized CodeFirst application which has been written using fairly strict MVVM ( which has a C#/WPF front-end and CodeFirst to MS SQL Server backend). I have written a load of helper classes in the Model, which create the DbContext, load objects and so on. I used to do this by generating a single DbContext per thread (in a static function) and obtaining that reference from the appropriate load function (Person.Load() would call GetDbContext). This worked quite nicely alongside

Fluent API, EF 4.1: a problem of inheritance and foreign key

百般思念 提交于 2019-12-13 00:14:13
问题 There are several simple classes: The first class: public class User { public int UserId { get; set; } public string Username { get; set; } // ... public ICollection<Topic> Topics { get; set; } } The second class: public class Publication { public int PublicationId { get; set; } public string Title { get; set; } / ... public User Author { get; set; } } The third class: public class Topic: Publication { public string TopicContent { get; set; } // ... } After creating a database for my model I

Code First can't map an override property

a 夏天 提交于 2019-12-12 20:14:48
问题 I have problems mapping a overrided property from a POCO object to database using TPH in Code First. My code is similar to these classes: public abstract class Vehicle { public int ID { get; set; } public abstract NumberOfWheels { get; set;} } public class Motorbike: Vehicle { public override NumberOfWheels { get; set; } } When I try to save the Motorbike class to Database I get the next message The property 'NumberOfWheels' is not a declared property on type 'Motorbike'. Verify that the

Table not mapped using EF code first approach

情到浓时终转凉″ 提交于 2019-12-12 16:56:56
问题 I'd like to use EF code first approach . I added the database and I generate the tables . Then I added this class public class Invitation { [Key] public int Id { get; set; } [DefaultValue(false)] public bool State { get; set; } public string Mail { get; set; } public string Tel { get; set; } public string Name { get; set; } public string Qr_code { get; set; } } I run these command then : add-migrations second update-database the Up and Down methods of the second class migration are empty!!

Code first self referencing foreign key (more than one)

一世执手 提交于 2019-12-12 16:42:33
问题 I have a User-Entity which has the EntityBase as parent class. The parent class looks like this: public class EntityBase { [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public Guid Id { get; set; } public bool? IsPublic { get; set; } public bool? IsActive { get; set; } public DateTime CreatedAt { get; set; } public DateTime? UpdatedAt { get; set; } public DateTime? DeletedAt { get; set; } public virtual User CreatedBy { get; set; } public Guid? CreatedById { get; set; } public virtual