c# - How can I use a custom method in a LINQ-to-SQL select clause? -


i described in this article. however, article 2006, , requires extension methods author wrote. i'm hoping there's more built-in @ point.

the intent here save method contains operations translatable t-sql , use assign specific properties in linq-to-sql select statement. if there's radically different way i've attempted, that's valid answer.

how do it?


what i've tried

i have query sort of this:

var thedata = (     inv in dc.inventory     inv.isdeleted == false     join data in cdc.inventorydatas     on inv.invkey equals data.reinvkey     data.recolkey == colkey     select new myclass {         serialnumber = inv.serialnumber,         data = inventorydata.dataexpression( data ),         name = inv.name,     } ); 

where inventorydata.dataexpression defined such:

public static expression<func<inventorydata, string>> dataexpression = (     d => d.textdata != null ? d.textdata          : d.integerdata != null ? d.integerdata.tostring()          : d.decimaldata != null ? d.decimaldata.tostring()          : d.datedata != null ? d.datedata.tostring()          : d.booleandata != null ? d.booleandata.tostring()         : null ); 

but it's not quite right. how can make work?

this works fine when select data 1 table, , when don't combine other expressions in right side of assignment statement same property:

data = inventorydata.dataexpression.compile()( data ) 

as do

select inventorydata.compileddataexpression( data ) 

and

select data.getdata() 

where compileddataexpression defined as

public static func<inventorydata, string> compileddataexpression      = inventorydata.dataexpression.compile(); 

and getdata defined as

public string getdata() {     // execute compiled delegete on inventorydata     var ret = inventorydata.compileddataexpression( );      return ret; } 

however, delegate not compiled t-sql. instead, whole objects of type associated table pulled, , delegate executed upon them locally.

i error when try full query, joins on other tables , assigns delegate 1 of several properties, of pull data other tables.


Comments

Popular posts from this blog

java - Spring Data JPA: Why findOne(id) executing delete query internally? -

python - Mongodb How to add addtional information when aggregating? -

java - Incorrect order of records in M-M relationship in hibernate -