1: create procedure sp_getItems (Dragging it into the diagram in the designer, we get the following prototype:
2:
3: query xml - <query> <id> 12 </ id> <id> 13 </ id> </ query>
four:
5:) as
6:
7: begin
eight:
9: select [Id], [Name], [Description]
ten:
11: from [Item] it
12:
13: inner join ( select tc value ( '.' , Bigint) [requestedid] from query. Nodes ( 'query / id' ) t (c)) as query on query.requestedid = it. [Id];
14:
15: end ;
1: public System.Data.Linq.ISingleResultsp_getItems (System.Xml.Linq. XElement query) {...}
1: public class CatalogReader: DataContext
2: {
3: public CatalogReader (): base (System.Configuration. ConfigurationManager .ConnectionStrings [ "ConnectionString" ] .ConnectionString)
4: {}
5: }
6:
1: class ItemAnd we register directly the Proxy-method for calling the procedure:
2: {
3: public long Id { get ; set ; }
4: public string Name { get ; set ; }
5: public string Description { get ; set ; }
6: }
7:
1: [Function (Name = "sp_getItems" )]How to use it:
2: public ISingleResult <Item> GetItems ([Parameter (DbType = "xml" )] string query)
3: {
4: var result = base .ExecuteMethodCall ( this , (System.Reflection.MethodInfo) System.Reflection.MethodInfo. GetCurrentMethod (), query);
5: return (ISingleResult <Item>) result.ReturnValue;
6: }
7:
1: using (CatalogReader context = new CatalogReader ())
2: return context.GetItems ( "<query> <id> 12 </ id> <id> 13 </ id> </ query>" );
3:
1: [Function (Name = "sp_getItems" )]Thus, it is possible to fully implement access to the database on LinqToSql technology (without using ADO.NET).
2: public ISingleResult <Item> GetItems ([Parameter (DbType = "xml" )] string query, [Parameter (DbType = "int output" )] ref int count)
3: {
4: var result = base .ExecuteMethodCall ( this , (System.Reflection.MethodInfo) System.Reflection.MethodInfo. GetCurrentMethod (), query);
5: count = ( int ) result. GetParameterValue (1);
6: return (ISingleResult <Item>) result.ReturnValue;
7: }
eight:
Source: https://habr.com/ru/post/40927/
All Articles