UPDATE语句中的未使用参数:LINQ to SQL

时间:2012-07-03 06:25:58

标签: c# .net vb.net linq linq-to-sql

我生成的SQL语句如下所示。请注意,参数@ p1和@ p2根本没有使用,也没有必要。为什么会这样?我们如何删除它们?

注意:对于所有列,UpdateCheck都是从不。

注意:数据库已正确更新。

ISSUE

UPDATE [dbo].[BankAccount]
SET [Status] = @p3
WHERE [BankAccountID] = @p0
-- @p0: Input Int (Size = -1; Prec = 0; Scale = 0) [10000]
-- @p1: Input NChar (Size = 10; Prec = 0; Scale = 0) [Fixed     ]
-- @p2: Input NChar (Size = 10; Prec = 0; Scale = 0) [Savings   ]
-- @p3: Input NChar (Size = 10; Prec = 0; Scale = 0) [FrozenFA]

自动生成的课程

[global::System.Data.Linq.Mapping.TableAttribute(Name="dbo.BankAccount")]
[InheritanceMapping(Code = "Fixed", Type = typeof(FixedBankAccount), IsDefault = true)]
[InheritanceMapping(Code = "Savings", Type = typeof(SavingsBankAccount))]
public partial class BankAccount : INotifyPropertyChanging, INotifyPropertyChanged

CREATE TABLE [dbo].[BankAccount](
[BankAccountID] [int] NOT NULL,
[AccountType] [nchar](10) NOT NULL,
[OpenedDate] [datetime] NULL,
[Status] [nchar](10) NULL,
[AccountOwnerID] [int] NULL,
CONSTRAINT [PK_BankAccount] PRIMARY KEY CLUSTERED 
(
[BankAccountID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

CODE

public class LijosSimpleBankRepository : ILijosBankRepository
{
    public System.Data.Linq.DataContext Context
    {
        get;
        set;
    }


    public List<DBML_Project.BankAccount> GetAllAccountsForUser(int userID)
    {
        IQueryable<DBML_Project.BankAccount> queryResultEntities = Context.GetTable<DBML_Project.BankAccount>().Where(p => p.AccountOwnerID == userID);
        return queryResultEntities.ToList();
    }

    public List<T> GetAllAccountsofType<T>() where T : DBML_Project.BankAccount
    {
        var query = from p in Context.GetTable<DBML_Project.BankAccount>().OfType<T>()
                    select p;

        List<T> typeList = query.ToList();
        return typeList;

    }

    public virtual void UpdateAccount(DBML_Project.BankAccount bankAcc)
    {
        //UPDATE statement will be called only if there has happened a change
        Context.SubmitChanges();
    }

}



namespace ApplicationService_Bank
{
public class BankAccountAppService
{
    public RepositoryLayer.ILijosBankRepository AccountRepository { get; set; }

    public void FreezeAllAccountsForUser(int userId)
    {
        IEnumerable<DBML_Project.BankAccount> accounts = AccountRepository.GetAllAccountsForUser(userId);
        foreach (DBML_Project.BankAccount acc in accounts)
        {

            string getTypeResult = Convert.ToString(acc.GetType());



            acc.Freeze();
            AccountRepository.UpdateAccount(acc);
        }

    }

}


}

1 个答案:

答案 0 :(得分:1)

所以它将鉴别器值包括为参数?据推测,在某些情况下在继承相关的更新中使用那些(可能作为并发检查的一部分,虽然看起来你已经禁用了它),而且它只是真的很难并且不值得在不需要它的情况下忽略它们,或者只是:一个bug悄悄进入。无论哪种方式,它都没有任何伤害,除了使查询稍微大一点。不足以引起注意。

相关问题