我有以下代码,即使在代码中第一次出现后它也会一直循环。Any
我想停止,但我无法申请
public List<FieldConfiguration> GetListOfProvisionsForBenefits(Dictionary<int, string> benefits)
{
StringBuilder sb = new StringBuilder();
sb.Append("SELECT ProvisionID ,BenefitID,ProvisionName, BPROV_Flags FROM BenefitProvisions WHERE");
int intSQLvar = 0;
string strSeperator = string.Empty;
foreach (KeyValuePair<int, string> benefit in benefits)
{
sb.AppendFormat(" {0} BenefitID=@benerfit{1}", strSeperator, intSQLvar);
intSQLvar++;
strSeperator = "OR";
}
SqlConnection con = new SqlConnection(m_strDBConnectionString);
SqlDataAdapter sqlDataAdapter = new SqlDataAdapter();
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = sb.ToString();
intSQLvar = 0;
foreach (KeyValuePair<int, string> benefit in benefits)
{
cmd.Parameters.Add(string.Format("@benerfit{0}", intSQLvar), SqlDbType.Int, 32).Value = benefit.Key.ToString();
intSQLvar++;
}
DataSet ds = new DataSet();
try
{
con.Open();
sqlDataAdapter.SelectCommand = cmd;
sqlDataAdapter.Fill(ds);
}
finally
{
if (con != null)
{
con.Close();
con = null;
}
}
List<ProvisionDetails> lstProvisions = new List<ProvisionDetails>();
if (ds != null && ds.Tables[0].Rows.Count > 0)
{
lstProvisions = (from r in ds.Tables[0].AsEnumerable()
select new ProvisionDetails()
{
ID = r.Field<int>("ProvisionID"),
Name = r.Field<string>("ProvisionName"),
BenefitID = r.Field<int>("ProvisionID"),
OptionValue = r.Field<int>("ProvisionID")
}).ToList();
if (benefits.Count == 1)
{
return (from p in lstProvisions
select new FieldConfiguration()
{
Name = p.Name,
ProvisionFieldID = p.ID.ToString(),
FieldType = Configuration.SyncapayPlus.FieldType.Provision,
Caption = (from b in benefits
where(b.Key == p.BenefitID)
select string.Format("{0}_{1}", b.Value, p.Name)).ToString() // to do change caption benefitname_provisionName
}).ToList();
}
else
{
return (from p in lstProvisions.GroupBy(x => x.Name)
.Where(y => y.Count() > 1)
.SelectMany(z => z)
select new FieldConfiguration()
{
Name = p.Name,
ProvisionFieldID = p.ID.ToString(),
FieldType = Configuration.SyncapayPlus.FieldType.Provision,
SourceOption = p.OptionValue.ToString(),
Caption =
(from b in benefits
where (b.Key == p.BenefitID)
select string.Format("{0}_{1}", b.Value, p.Name)).ToString() // to do change caption benefitname_provisionName
}).ToList();
}
}
return null;
}
我想在获得标题的本节中应用任何内容;当我找到第一个好处时,我希望它退出并分配它:
Caption =
(from b in benefits
where (b.Key == p.BenefitID)
select string.Format("{0}_{1}", b.Value, p.Name)).ToString() // to do change caption benefitname_provisionName
}).ToList();
}