Tuesday, 15 January 2013

Derived Class Properties Getting Passed to SQL Server via Entity Framework -



Derived Class Properties Getting Passed to SQL Server via Entity Framework -

when retrieving list of objects sql server , getting next error:

system.data.sqlclient.sqlexception invalid column name 'accountname' invalid column name 'accountnumber'

i understand database not contain columns, don't believe code should passing columns retrieval.

i have class beingness derived , entity framework code-first class has few properties added it.

for reason, when create database call, passes properties created transactionhistorygrid class sql server, when should passing transactionhistory properties.

here code:

entity framework code-first class:

public partial class transactionhistory : transaction { public string billingaddresscity { get; set; } public string billingaddresscompany { get; set; } public string billingaddresscountry { get; set; } public string billingaddressfax { get; set; } public string billingaddressfirst { get; set; } public string billingaddresslast { get; set; } public string billingaddressphone { get; set; } public string billingaddressstate { get; set; } public string billingaddressstreet { get; set; } public string billingaddresszip { get; set; } [system.componentmodel.dataannotations.schema.notmapped] public address billingaddress { get; set; } [system.componentmodel.dataannotations.schema.notmapped] public address shippingaddress { get; set; } public system.guid id { get; set; } public virtual business relationship account { get; set; } }

class populate kendo grid:

public class transactionhistorygrid : transactionhistory { public string accountname { get; set; } public string accountnumber { get; set; } public static list<transactionhistorygrid> gettransactionhistorygrid() { list<transactionhistorygrid> grids = new list<transactionhistorygrid>(); // problem begins: foreach (transactionhistory t in getalltransactionhistories()) { // doesn't create far. var grid = new transactionhistorygrid() { business relationship = t.account; accountname = t.account.accountname; accountnumber = t.account.accountnumber; }; grids.add(grid); } homecoming grids; } }

method retrieve data:

public static list<transactionhistory> getalltransactionhistories() { using (databasecontext context = new databasecontext()) { // error gets thrown here... why properties beingness read?? homecoming context.set<transactionhistory>().tolist(); } }

usage controller:

public actionresult transactionhistory_read([datasourcerequest]datasourcerequest request = null) { list<transactionhistorygrid> transactionhistory = transactionhistorygrid.gettransactionhistorygrid(); datasourceresult result = transactionhistory.todatasourceresult(request); homecoming json(result, jsonrequestbehavior.allowget); }

thoughts? suggestions?

this sql server profiler returns:

(accountname, accountnumber, , transactionhistorygrid should never sent sql. why it?)

select 1 [c1], [extent1].[discriminator] [discriminator], ... [extent1].[accountname] [accountname], [extent1].[accountnumber] [accountnumber], [extent1].[account_id] [account_id], [extent1].[billingstatement_id] [billingstatement_id] [dbo].[transactionhistories] [extent1] [extent1].[discriminator] in (n'transactionhistorygrid',n'transactionhistory')

reposting comment thread:

type discovery described here @ play. [notmapped] attribute has attributetargets.class, attributetargets.property , attributetargets.field flags, unless ever intend manipulate transactionhistorygrid properties straight via databasecontext, set attribute on entire class.

[notmapped] public class transactionhistorygrid : transactionhistory { ... }

the alternative move transactionhistorygrid class assembly.

sql entity derived

No comments:

Post a Comment