code-first

Custom non-primitive type in Entity Framework code-first 4.1

陌路散爱 提交于 2020-01-05 08:07:27
问题 I have this custom type: public struct PasswordString { private string value; public PasswordString(string value) { this.value = MD5.CalculateMD5Hash(value); } public string Value { get { return this.value; } set { this.value = MD5.CalculateMD5Hash(value); } } public static implicit operator PasswordString(string value) { return new PasswordString(value); } public static implicit operator string(PasswordString value) { return value.Value; } public static bool operator ==(string x,

Programmatically creating a connection string for mapping an Entity Framework Code-First model with an existing Sql Server Compact database

北城余情 提交于 2020-01-05 07:38:36
问题 I've successfully mapped an Entity Framework Code-First data model with an existing Sql Server Compact database by a declarative approach using app.config but it would be great if I could build such connection programmatically with perhaps the help of the EntityConnectionStringBuilder (System.Data.EntityClient) class. Unfortunately this approach is not working as the [DbContext].Connection.ConnectionString is not accepting most of its properties. Here's the actual working code with the faulty

EF code first from database 0..1 to many relationship

人走茶凉 提交于 2020-01-03 12:13:10
问题 I am trying to generated an entity framework code first model from an existing database (without changing the database schema). This database has been used in the past to generate edmx models and I am trying to achieve the equivalent model using Fluent Api or data annotations. The relationship I have been unable to reproduce is 0..1 to many using a join table (not a nullable foreign key). So it would look something like this: TableA { ID (PrimaryKey) TableB (0 or 1) } JoinTable { TableA_FK

Cascade Delete, same table, Entity Framework 4 Code First

白昼怎懂夜的黑 提交于 2020-01-02 03:42:05
问题 Hi Im currently working with .sdf database (Server Compact Version 4.0) and sql express. I'm trying to setup a cascade delete on a same table (category - sub category) but I get that I cant add relation to the same table. A foreign key constraint had and update or a delete cascade rule, and self-references a column in the same table, is not allowed What can I do about this? EDIT I'm the only one with this problem? 回答1: As your SQLException suggested, this is a limitation of SQL Server in

Entity Framework - The foreign key component … is not a declared property on type

与世无争的帅哥 提交于 2020-01-01 23:36:48
问题 I have the following Model public class FilanthropyEvent : EntityBase, IDeleteable { public int Id { get; set; } public string Name { get; set; } public DateTime EventDate { get; set; } public string Description { get; set; } public decimal Target { get; set; } public decimal EntryFee { get; set; } public bool Deleted { get; set; } public ICollection<EventAttendee> EventAttendees { get; set; } } public class Attendee : EntityBase, IDeleteable { public int Id { get; set; } public string Email

Entity Framework - The foreign key component … is not a declared property on type

牧云@^-^@ 提交于 2020-01-01 23:35:28
问题 I have the following Model public class FilanthropyEvent : EntityBase, IDeleteable { public int Id { get; set; } public string Name { get; set; } public DateTime EventDate { get; set; } public string Description { get; set; } public decimal Target { get; set; } public decimal EntryFee { get; set; } public bool Deleted { get; set; } public ICollection<EventAttendee> EventAttendees { get; set; } } public class Attendee : EntityBase, IDeleteable { public int Id { get; set; } public string Email

Entity Framework Core Code-First: Cascade delete on a many-to-many relationship

血红的双手。 提交于 2020-01-01 08:55:53
问题 I'm working on an ASP.NET MVC 6 project with Entity-Framework Core (version "EntityFramework.Core": "7.0.0-rc1-final" ) backed by a SQL Server 2012 express DB. I need to model a many-to-many relationship between a Person entity and an Address entity. As per this guide I modeled it with a PersonAddress join-table entity, because this way I can store some extra info. My goal is to set-up my system this way: If a Person instance is deleted, all the related PersonAddress instances must be deleted

Use ASP.NET Membership in ServiceStack

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-01 05:37:05
问题 how can i use asp.net membership in ServiceStack ? (ServiceStack.OrmLite , ServiceStack.Host.AspNet , etc ) 回答1: You can host ServiceStack on a custom path, i.e. at /api which lets you run ASP.NET web forms and ServiceStack side-by-side and then use the normal ASP.NET membership provider in ASP.NET. You can then share UserSessions with ServiceStack using its Session Provider, here's an example on how to instantiate a Session with MVC - you can use this same class with ASP.NET. The alternative

Entity Framework Code First - Configuration in another file

落花浮王杯 提交于 2020-01-01 05:19:05
问题 What is the best way to separate the mapping of tables to entities using the Fluent API so that it is all in a separate class and not inline in the OnModelCreating method? What I am doing currently: public class FooContext : DbContext { // ... protected override OnModelCreating(DbModelBuilder modelBuilder) { modelBuilder.Entity<Foo>().Property( ... ); // ... } } What i want: public class FooContext : DbContext { // ... protected override OnModelCreating(DbModelBuilder modelBuilder) {

Disabling Entity Framework's default value generation (Code First)

≡放荡痞女 提交于 2020-01-01 04:45:12
问题 I have a column in the database that cannot be null, and I want to set it to have a default value in the database . The problem is that entity framework seems to create a default value itself (for example, int => 0), and completely ignores the default value constraint in the database. Is there any way to disable this default valuing of entity framework? 回答1: Natively, Entity framework do not allows this. You have to do some code to it. This answer from another site seems to had solved the