c# - Getting NULL for a row a type nvarchar when I try to use LINQ to mirror my database -


i have table created

create table orgs ( o_id int not null identity(1,1), orgname nvarchar (max) not null, primary key (o_id) ); 

and few rows of initialized with

insert orgs (orgname) values ('someorg'); insert orgs (orgname)  values ('otherorg'); 

i've looked in visual studio's server object explorer make sure table , columns , 2 rows created.

my model mirrors table is

[table(name = "orgs")] public class organization {     public organization()     {      }      [column]     public int o_id { get; set; }     public string orgname { get; set; } }   

in controller have, test,

portaldata pd = new portaldata(); foreach (organization x in pd.orgs) {     viewbag.orgsinfo += ("o_id=" + (x.o_id).tostring() + ", org=" + x.orgname + "\n"); } 

the problem (x.o_id).tostring() spitting out correct value x.orgname undefined.

my hypothesis has intermediate conversion needs take place data type of column used c# string.

edit: added code portaldata below

using system; using system.collections.generic; using system.linq; using system.web; using system.data.linq; using system.data.linq.mapping;  namespace allyportal.models {     [database]     public class portaldata : datacontext     {         public portaldata()             : base("...")         {         }         public table<assetlink> links;         public table<assetfile> files;         public table<organization> orgs;         public table<category> cats;             }         [table( name = "links")]     public class assetlink     {         public assetlink()         {          }          [column]         public int rownum { get; set; }         [column]         public int linkid { get; set; }         [column]         public int fileid { get; set; }      }      [table( name = "files" )]     public class assetfile     {         public assetfile()         {          }          [column]         public int fileid { get; set; }         public string org { get; set; }         public string category { get; set; }         public string loc { get; set; }     }      [table(name = "orgs")]     public class organization     {         public organization()         {          }          [column]         public int o_id { get; set; }         public string orgname { get; set; }     }       [table(name = "cats")]     public class category     {         public category()         {          }          [column]         public int o_id { get; set; }         public string cat { get; set; }     }    } 

from the msdn documentation:

use attribute designate member of entity class represent column in database table. ... entity class members identified columns persisted when linq sql saves changes database.

that suggest need add [column] attribute all of properties in assetfile, organization , category classes. without attribute, value of properties not loaded from, or persisted to, database.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -