c# - How to stop the creation of a table when mapping to a stored proc MVC -


i have codefirst mvc 5 application. there spatial query involved, have wrapped in stored proc.

using new class, i've mapped results of stored proc call model use in views.

however, codefirst wants create new table model class. how prevent that? should bother (i'm never writing table or updating table.)

model class:

public class conflict {     [key, column(order=0)]     public int projectid { get; set; }      [key, column(order=1)]     public int conflictprojectid { get; set; }      [datatype(datatype.date)]     [displayformat(dataformatstring = "{0:dd/mm/yyyy}")]     [display(name="start")]     public datetime startdate { get; set; }      [datatype(datatype.date)]     [displayformat(dataformatstring = "{0:dd/mm/yyyy}")]     [display(name = "end")]     public datetime enddate { get; set; }      public virtual project project { get; set; }  } 

stored proc call:

public actionresult index(int d = 0, int r = 0, int p = 0, bool future = false) {     var daybufferparameter = new sqlparameter("@daybuffer", d);     var distbufferparameter = new sqlparameter("@distbuffer", r);      var result = db.database.sqlquery<conflict>("getallconflicting @daybuffer, @distbuffer",         daybufferparameter, distbufferparameter)         .where(proj => p == 0 || proj.projectid == p)         .where(proj => !future || proj.enddate >= datetime.now).tolist();      return view(result); } 

dbcontext:

public class applicationdbcontext : identitydbcontext<applicationuser> {     public applicationdbcontext()         : base("defaultconnection", throwifv1schema: false)     {     }      public static applicationdbcontext create()     {         return new applicationdbcontext();     }      public system.data.entity.dbset<n.models.project> projects { get; set; }      public system.data.entity.dbset<n.models.conflict> conflicts { get; set; } } 

generated migration (what don't want!):

public partial class conflicts : dbmigration {     public override void up()     {         createtable(             "dbo.conflicts",             c => new                 {                     projectid = c.int(nullable: false),                     conflictprojectid = c.int(nullable: false),                     startdate = c.datetime(nullable: false),                     enddate = c.datetime(nullable: false),                 })             .primarykey(t => new { t.projectid, t.conflictprojectid })             .foreignkey("dbo.projects", t => t.project_projectid)             .index(t => t.conflictproject_projectid)             .index(t => t.project_projectid);      }      public override void down()     {         dropforeignkey("dbo.conflicts", "project_projectid", "dbo.projects");         dropforeignkey("dbo.conflicts", "conflictproject_projectid", "dbo.projects");         dropindex("dbo.conflicts", new[] { "project_projectid" });         dropindex("dbo.conflicts", new[] { "conflictproject_projectid" });         droptable("dbo.conflicts");     } } 


Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -