1

我有如下生成的 SQL 语句。请注意,参数@p1 和@p2 根本没有使用,也不需要。为什么会来?我们怎样才能删除它们?

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

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

问题

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]

代码

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);
        }

    }

}


}
4

1 回答 1

1

所以它包括鉴别器值作为参数?大概在某些情况下,它会在与继承相关的更新中使用它们(也许作为并发检查的一部分,尽管看起来您已经禁用了它),并且在这种情况下忽略它们真的很难而且不值得在不需要它的地方,或者只是:一个错误爬进来。无论哪种方式,它都不会造成任何伤害,除了使查询稍微大一点。不足以引起注意。

于 2012-07-03T06:38:28.357 回答