I have SQL statements generated like the following. Note that the parameters @p1 and @p2 are not at all used and no way needed. Why is it coming? How can we remove them?
Note: UpdateCheck is Never for all columns.
Note: The database is updated correctly.
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]
Auto generated class
[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
TABLE
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);
}
}
}
}
So it is including the discriminator values as parameters? Presumably there are some cases where it uses those in an inheritance-related update (perhaps as part of concurrency checking, although it looks like you’ve disabled that), and it was simply really hard and not worth it to ignore them in the cases where it wasn’t needed, or simply: a bug crept in. Either way, it doesn’t do any harm, other than making the query a tiny tiny bit larger. Not enough to notice.