zoukankan      html  css  js  c++  java
  • Linq使用数据库存储过程

    在使用linq to SQL 的时候,我们常用一些复杂的复杂的sql语句,但是结果总是不如我们所愿。报错。。。

    后来发现,原来在使用的时候,我们还是需要一些特殊设置的

    [Function(Name = "dbo.fn_getpy", IsComposable = true)]
    [return: Parameter(DbType = "nvarchar(400) ")]
    public string ConvertChineseToPinyin([Parameter(Name = "str", DbType = "nvarchar(100)")]string @str)
    {
          return (string)this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())), @str).ReturnValue;
    }

    然后,我们再去使用。。。貌似可以了。。。

    顺便把别人写的sql也贴出来吧。。。

     1 use Platform;
     2 
     3 create function [dbo].[fn_getpy](@str   nvarchar(100)) 
     4 returns nvarchar(400) 
     5 as 
     6 begin 
     7 declare @str_len int,
     8     @result nvarchar(400),
     9     @crs nvarchar(1)
    10 set @str_len=len(@str)
    11 set @result= ' ' 
    12     while   @str_len> 0 
    13     begin 
    14 set  @crs=substring(@str,@str_len,1)
    15  
    16    select  @str_len=@str_len-1,@result=
    17      case  
    18      when @crs>='' then 'Z'
    19      when @crs>='' then 'Y'
    20      when @crs>='' then 'X'
    21      when @crs>='' then 'W'
    22      when @crs>='' then 'T'
    23      when @crs>='' then 'S'
    24      when @crs>='' then 'R'
    25      when @crs>='' then 'Q'
    26      when @crs>='' then 'P'
    27      when @crs>='' then 'O'
    28      when @crs>='' then 'N'
    29      when @crs>='' then 'M'
    30      when @crs>='' then 'L'
    31      when @crs>='' then 'K'
    32      when @crs>='' then 'J'
    33      when @crs>='' then 'H'
    34      when @crs>='' then 'G'
    35      when @crs>='' then 'F'
    36      when @crs>='' then 'E'
    37      when @crs>='' then 'D'
    38      when @crs>='' then 'C'
    39      when @crs>='' then 'B'
    40      when @crs>='' then 'A'
    41      else  @crs  end+@result
    42     end 
    43     return(@result) 
    44 END
    View Code
  • 相关阅读:
    定位IO瓶颈的方法,iowait低,IO就没有到瓶颈?
    10分钟检查自己的系统性能数据
    netperf使用指南
    如何看内核源码
    xxx
    os.path 模块
    目前中国智能语音产业的格局、现状
    NLP-python 自然语言处理01
    15本经典金融投资著作
    写给步入工作的自己
  • 原文地址:https://www.cnblogs.com/ArrowTip/p/ChineseToPinyin.html
Copyright © 2011-2022 走看看