Context: saasreportprocontext CTX = factory. saasreportprocontextfactory. getsaasreportprocontext ();
There are three parameters: String reportname, string module, string type
In LINQ to SQL
VaR query = from o in CTX. reportor
WhereO. reportor_name.contains (reportname)
&&O. reportor_module.contains (module)
&&O. reportor_type.contains (type)
Select O;
Translate into SQL
Select * from XXX Where reportor_name like '% x % '.........
Write the following code on the fly in the LINQ to Oracle directory:
VaR query = from o in CTX. reportor
Where (string. isnullorempty (reportname )? True: reportname. Contains (O. reportor_name ))
& (String. isnullorempty (module )? True: module. Contains (O. reportor_module ))
& (String. isnullorempty (type )? True: type. Contains (O. reportor_type ))
In this case, I will replace Oracle with the SQL Server database, all queriesCodeIf you want to rewrite it, it is impossible to transplant it.
Originally, the eforacleprovider project is an open-source project that is better suited to the use of LINQ to Oracle. It seems that you have to modify and implement it on your own.
Later, I thought about the problem of updating and maintaining the open-source framework after it was updated. So I directly wrote the subordinate code to solve the problem:
1. Interface: ilikebridge
Code
/// <Summary>
/// This class is defined mainly to solve the problem of calling functions such as LINQ ins () and stratwith () in LINQ to Oracle, which is the opposite of calling functions such:
/// So building a bridge, all like passing through this bridge turn
/// When the database is changed to SQL or another database, modify this type or configuration.
/// </Summary>
Public Interface Ilikebridge
{
Bool Likeleft ( String Field, String Value );
BoolLikeright (StringField,StringValue );
BoolLikeall (StringField,StringValue );
}
2. ora implementation
Code
Public Class Likebridgeora: ilikebridge
{
Public Bool Likeleft ( String Field, String Value)
{
// Oracle
Return (String. isnullorempty (value) ? True : Value. startswith (field ));
}
Public Bool Likeright ( String Field, String Value)
{
// Oracle
Return (String. isnullorempty (value) ? True : Value. endswith (field ));
}
Public Bool Likeall ( String Field, String Value)
{
// Oracle
Return (String. isnullorempty (value) ? True : Value. Contains (field ));
}
}
3. SQL implementation
Code
Public Class Likebridgesql: ilikebridge
{
Public Bool Likeleft ( String Field, String Value)
{
Return Field. startswith (value );
}
Public BoolLikeright (StringField,StringValue)
{
ReturnField. endswith (value );
}
Public BoolLikeall (StringField,StringValue)
{
ReturnField. Contains (value );
}
}
4. Factory
Code
Public Class Likebridgefactory
{
Private Static Ilikebridge Bridge = Null ;
Public Static Ilikebridge getlikebridge ()
{
If (Bridge = Null )
{
Object OBJ = Assembly. getexecutingassembly (). createinstance (system. configuration. configurationmanager. deleettings [ " Likebridgeprovider " ]);
Bridge = OBJ As Ilikebridge;
}
Return Bridge;
}
}
5. Add the key "likebridgeprovider" value = "xx. xx. likebridgeora" in X. config"
6. call:
VaR query = from o in CTX. reportor
Where LINQ. likebridgefactory. getlikebridge (). likeall (O. reportor_name, reportname)
& LINQ. likebridgefactory. getlikebridge (). likeall (O. reportor_module, reportname)
& LINQ. likebridgefactory. getlikebridge (). likeall (O. reportor_type, type)
Select O;