Questions tagged [ef-model-builder]

58 questions
0
votes
1 answer

"One of X"-to-One Entity Relationship

I have three distinct well-defined entities, Foo, Bar, Baz, on one side of the relationship, and a single entity these all need to be tied to on the other side, lets call it LogEntry. I have the relationship working as far as sql is concerned, but…
Jecoms
  • 2,558
  • 4
  • 20
  • 31
0
votes
1 answer

How to read from a table that is mapped with ModelBuilder in mvc c#

I have a Dbcontext where in its OnModelCreating() method I have something like this: modelBuilder.Entity().HasMany(m => m.CmsKeywords).WithMany(m => m.CmsContentDatas).Map(m => { …
0
votes
0 answers

Cascade Deletion of Connected tables

I'm developing a DataBase on MS SQL Server with EF 6 - Code First I have schema like so: Ads|Messages|Attachments where Ads has many Messages Ads has many Attachments Messages has many Attachments The Attachments table has 2 FKs one to Ads and one…
Stefan PEev
  • 481
  • 5
  • 17
0
votes
0 answers

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

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 =…
0
votes
0 answers

Set discriminator property in subclass - Entity Framework

I have the following problem. I'm building TPH inheritance with Entity Framework and I need to set discriminator column on existing property of subclass. Example: public abstract class Building { //... some properties public BuildingType…
chobotek
  • 77
  • 2
  • 6
0
votes
2 answers

Have specific property configuration for all types that implement an interface except for one

I have a number of Types that inherit from the Interface 'IEventReportElement', which exposes the property 'IdEventReport': public interface IEventReportElement { long Id { get; set; } long? IdEventReport { get; set; } } This is a nullable…
DevilSuichiro
  • 1,049
  • 8
  • 21
0
votes
1 answer

EF6 Set MaxLength of a property based on attribute of the containing class

Situation: I have a base class Lookup, as follows: public abstract class Lookup : DeactivatableDomainModel { [Required] [Key] public int ID { get; set; } [Required] public string Description { get; set; } [Required] …
Bit Herder
  • 33
  • 7
0
votes
1 answer

EF6 Code First Composite Primary AND Foreign Keys: Foreign Key must be mapped

Well, after a morning of beating my head against the wall, I'm tossing this out there. I have a DB Table (Table1) with a composite PK (Column1, Column2, Column3). (Column1,Column3) is ALSO a FK to another table (Table2). Trying to use Code First…
0
votes
1 answer

Unable to add DbModelBuilder and .HasRequired() to modelBuilder

I am trying to create a ModelBuilder within my API and can't seem to add .HasRequired() to my code. I am assuming this is due to the fact that it lives within DBModelBuilder, however, I cannot add that also. It will only allow me to use…
Riples
  • 1,167
  • 2
  • 21
  • 54
0
votes
1 answer

HasMany and WithRequired extension methods not found

I am building my data layer class library with Entity Framework 6.1. I created my context and am trying to do the model builder code (or is it derived when I do Add-Migration? Anyway, I have seen quite some examples but when I try to use .HasMany or…
Lord of Scripts
  • 3,579
  • 5
  • 41
  • 62
0
votes
0 answers

Entity Framework ModelBuilder multiple joins/subquery

I have been working on how to map an entity property to a column in another table using multiple joins (or a subquery), but I am really struggling to find where to start. I have create a SQL Fiddle that demonstrates what I want to do. A User entity…
Luke T O'Brien
  • 2,565
  • 3
  • 26
  • 38
0
votes
1 answer

Entity Framework - table needs two foreign keys pointing at same table

I am working on an existing project with a database containing a table of "Contacts" : Id, FirstName, LastName, MobileNumber etc. I am now wanting to implement a table whereby I can link pairs of Contacts together. I have built a class called…
0
votes
1 answer

In Entity Framework how do I unit test dbmodel construction without actually connecting to a db?

I have a class inheriting from DbContext implementing a code-first Entity Framework object. I would like to have a unit test that exercises the model builder in this dbcontext -- this would be useful for detecting things like 'key not defined on…
Clyde
  • 8,017
  • 11
  • 56
  • 87
1 2 3
4