c# - Incompatible Data Reader -


using mvc 4 ef 5x , new them.

my entities , contexts etc created automatically in vs 2010 existing database when try result through raw sql query getting error:

the data reader incompatible specified 'platinummodel.sales_journal'. member of type, 'line_no', not have corresponding column in data reader same name. 

the stack exchange solutions related error ( the data reader incompatible . member not... ) have suggested error caused when there missing column or model edmx needs updating (which have done although there no need database has not been altered)

sales_journal.cs - part of platinum.tt file

namespace ppos_mvc_site.models {     using system;     using system.collections.generic;      public partial class sales_journal     {         public int line_no { get; set; }         public nullable<system.datetime> date_time { get; set; }         public nullable<byte> workstation_no { get; set; }         public nullable<short> user_no { get; set; }         public nullable<int> trans_no { get; set; }         public nullable<int> invoice_no { get; set; }         public string account_no { get; set; }         public string product_code { get; set; }         public string department_no { get; set; }         public nullable<float> qty { get; set; }         public nullable<float> pack_size { get; set; }         public nullable<float> ave_cost { get; set; }         public nullable<float> sales_tax { get; set; }         public nullable<byte> tax_type { get; set; }         public nullable<float> discount_amt { get; set; }         public nullable<float> dicount_value { get; set; }         public nullable<float> line_total { get; set; }         public nullable<float> function_key { get; set; }         public nullable<byte> location { get; set; }         public nullable<bool> stock_level { get; set; }         public nullable<int> branch_no { get; set; }         public nullable<int> cashup_no { get; set; }         public string { get; set; }         public nullable<decimal> table_no { get; set; }         public nullable<decimal> tab_no { get; set; }         public nullable<int> covers { get; set; }         public nullable<int> user_overide { get; set; }         public string room_no { get; set; }         public string res_no { get; set; }         public string instructions { get; set; }         public string order_no { get; set; }         public nullable<int> points { get; set; }         public string time_placed { get; set; }         public nullable<int> jobcard_no { get; set; }         public nullable<int> quote_no { get; set; }         public string serial_no { get; set; }     } } 

sales_journal sql creation code

create table [dbo].[sales_journal](     [line_no] [int] identity(1,1) not null, [date_time] [datetime] null, [workstation_no] [tinyint] null, [user_no] [smallint] null, [trans_no] [int] null, [invoice_no] [int] null, [account_no] [nvarchar](16) null, [product_code] [nvarchar](25) null, [department_no] [nvarchar](10) null, [qty] [real] null, [pack_size] [real] null, [ave_cost] [real] null, [sales_tax] [real] null, [tax_type] [tinyint] null, [discount_amt] [real] null, [dicount_value] [real] null, [line_total] [real] null, [function_key] [real] null, [location] [tinyint] null, [stock_level] [bit] null, [branch_no] [int] null, [cashup_no] [int] null, [extra] [nvarchar](50) null, [table_no] [numeric](10, 1) null, [tab_no] [numeric](10, 1) null, [covers] [int] null, [user_overide] [int] null, [room_no] [char](10) null, [res_no] [char](10) null, [instructions] [nvarchar](250) null, [order_no] [varchar](40) null, [points] [int] null, [time_placed] [varchar](5) null, [jobcard_no] [int] null, [quote_no] [int] null, [serial_no] [varchar](25) null,     constraint [pk_sales_journal] primary key clustered      (         [line_no] asc     )with (pad_index  = off, statistics_norecompute  = off, ignore_dup_key = off, allow_row_locks  = on, allow_page_locks  = on, fillfactor = 90) on [primary] ) on [primary] 

controller code trying interact this

public void calculatebasicdaydata() {     string ssqlcash = "select * sales_journal function_key = 9 , convert(datetime, floor(convert(float, date_time))) = '" + this.targetdate.tostring() + "'";     string ssqlcashcount = "select count(sales_journal.line_no) sales_journal function_key = 9 , convert(datetime, floor(convert(float, date_time))) = '" + this.targetdate.tostring() + "'";     var sjournalcash = platcontext.sales_journal.sqlquery(ssqlcash);      this.numberofcashsales = platcontext.sales_journal.sqlquery(ssqlcashcount).count();     this.totalcash = this.calculatedaytotalsales(sjournalcash); }  private decimal calculatedaytotalsales(system.data.entity.infrastructure.dbsqlquery<sales_journal> sj) {     decimal cashtotal = 0;      foreach (var jitem in sj.tolist())     {         cashtotal += decimal.parse(jitem.line_total.tostring());     }      return cashtotal; } 

you're trying 'cast' count sales_journal object, not work:

platcontext.sales_journal.sqlquery(ssqlcashcount).count() 

that sql query returns integer tries create sales_journal object from.

have tried using linq instead? like:

this.numberofcashsales =     platcontext.sales_journal.count(s => s.function_key == 9 &&                                          (s.date_time != null &&                                           s.date_time >= this.targetdate.date &&                                          s.date_time < this.targetdate.date.adddays(1))); 

that gives typed queries without need of writing sql queries in code (which lot harder debug!).


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -