我有如下生成的 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);
}
}
}
}