c# - Code First Complex Type Or Foreign Key Relationship? -
i'm writing mvc5 application ef6 allows users enter job timesheets, job notes , email customer update.
i want database structure compose of 3 tables (timers, jobnotes , emails). can have 3 models this;
[table("timers")] public partial class timermodel { public int id { get; set; } public string user { get; set; } ...etc public virtual customeremailmodel customeremail { get; set; } } [table("jobnotes")] public partial class jobnotemodel { public int id { get; set; } [column("username")] public string user { get; set; } ...etc public virtual customeremailmodel customeremail { get; set; } } [complextype] public partial class customeremailmodel { [display(name = "email customer?")] public bool sendemail { get; set; } [datatype(datatype.emailaddress)] public string { get; set; } public string subject { get; set; } [datatype(datatype.multilinetext)] public string body { get; set; } }
but doens't create email table, , instead adds properties timer , jobnotes tables (e.g. email_sendemail, email_to, etc).
if remove [complextype] annotation, , change other models have;
public int? emailid { get; set; } [foreignkey("emailid")] public virtual customeremailmodel customeremail { get; set; }
then create table, i'm unsure of how add new entries (i.e. emails added on fly, 0..1 relationship. mean need add email explicitly, added entries id, , assign other model (timer or jobnote model) emailid.
is there better way of doing this?
thanks in advance. please let me know if need further information.
edit: seems need provide more information answers i'm getting far. have 2 databases in play. vendor supplied database, application records job, timesheet, employee, customer, etc information. lets call db01. , database (call db02) application (its mobile app users record timesheet or jobnote information, , submit db01).
the mobile app has user interface has following key inputs; start time, stop time, break time, job selector (drop down), timesheet title, timesheet notes, send email customer (checkbox), address, subject, body.
as such, complex type work correctly (and i'm using in interm). however, because have page able email customer well, wanted separate email table (however, don't want have save email separately, , assign timesheet or jobnote).
also - tables need (for db02), ones store timesheet, jobnote , email data. once timesheet or jobnote gets submitted, can deleted or archived. need these tables, because other relevant information contained in db01. can retrieve data views on db02, , can submit information db02 db01 stored procedure db02. (db02 has db01 linked server)
this simple example of use of foreign keys ef6
public class { public int id { get; set; } public virtual b bobject { get; set; } public int bid; public virtual icollection<c> cs { get; set; } } public class b { public int id { get; set; } public string name { get; set; } public virtual icollection<a> { get; set; } } } public class c { public int id { get; set; } public string transactionid { get; set; } public virtual aobj { get; set; } public int aid { get; set; } }