asp.net - Can I split a SQL table into three classes using EF 6.1 and SQL Server 2012? -


i have following class simplified example. class has id , properties related house , related room. data stored in 1 row of sql table.

namespace classlibrary1.models {     public partial class aspnetuser     {         public string id { get; set; }         public nullable<int> adminhousenumber { get; set; }         public string adminhousecity { get; set; }         public nullable<int> adminroomnumber { get; set; }         public string adminroomfloor { get; set; }     } } 

sql:

create table [dbo].[aspnetusers] (     [id]                   nvarchar (128) not null,     [adminhousenumber]     int            null,     [adminhousecity]       nchar (10)     null,     [adminroomnumber]      int            null,     [adminroomfloor]       nchar (10)     null,     constraint [pk_dbo.aspnetusers] primary key clustered ([id] asc) ); 

this maps database this:

namespace classlibrary1.models.mapping {     public class aspnetusermap : entitytypeconfiguration<aspnetuser>     {         public aspnetusermap()         {             // primary key             this.haskey(t => t.id);              // properties             this.property(t => t.id)                 .isrequired()                 .hasmaxlength(128);              // table & column mappings             this.totable("aspnetusers");             this.property(t => t.id).hascolumnname("id");             this.property(t => t.adminhousenumber).hascolumnname("adminhousenumber");             this.property(t => t.adminhousecity).hascolumnname("adminhousecity");             this.property(t => t.adminroomnumber).hascolumnname("adminroomnumber");             this.property(t => t.adminroomfloor).hascolumnname("adminroomfloor");         }     } } 

for performance reasons keep data in 1 table. possible me create 2 additional classes. 1 house , 1 room , have 3 classes link same table?

namespace classlibrary1.models {     public partial class aspnetuser     {         public string id { get; set; }         public string roomid { get; set; }         public string houseid { get; set; }         public virtual house { get; set; }         public virtual room { get; set; }         public class house            public string houseid { get; set; }            public nullable<int> adminhousenumber { get; set; }            public string adminhousecity { get; set; }        }         public class room            public string roomid { get; set; }            public nullable<int> adminroomnumber { get; set; }            public string adminroomfloor { get; set; }        }      } } 

it seems you're looking called complextypes support, googling showed this basic article


Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -