c# - How to convert Enumerable value to right format? -
i have following code:
client data = this.controllerpacients.getbyid(id).asenumerable() .select(row => new client { taxcode = convert.toint32(row.field<int>("taxcode")).tostring() }) .single(); so, in database field taxcode integer. in model client string.
i error in line, when try convert types:
system.invalidcastexception: 'specified cast not valid.'
attachment:
i tried way also:
datatable data = db.getdatatable("select * table id =4"); var c = data.rows[0].field<int>("taxcode");
i have reply question inappropriate answer... i'm going break question down , explain why it's horrible question...
in code:
client data = this.controllerpacients.getbyid(id).asenumerable() .select(row => new client { taxcode = convert.toint32(row.field<int>("taxcode")).tostring() }) .single(); ... fail explain of it. here points:
a) controllerpacients you've spelled incorrectly way, class-level property hiding cast within it, meaning we'd never able see bug here on stack overflow. should provide entire code, or fill in gaps explanation.
b) getbyid(id) returns array-like type, can't see is. using anenumerable in situation has serious code-smell. isn't there way can select directly getbyid result, or access appears row collection via property of getbyid result?
c) 25 thousand casts... if field int , class has string, use .tostring() don't need conversion going on.
d) should consider creating method on client class takes patient parameter , loads it's values that, rather loading original patient's datasource. example client.loadtaxcodefrompatient(patient)
e) you're having put single() call @ end of shouldn't collection anyway, if getbyid returns other patient class it's doing wrong.
sorry beating question that, gotta :)

Comments
Post a Comment