简体   繁体   English

Linq的InsertOnSubmit没有添加到changeset

[英]Linq's InsertOnSubmit not added to changeset

Related to How to debug a linq to sql InsertOnSubmit statement? 有关如何调试linq到SQL的InsertOnSubmit语句?

I Execute the following bit of code: 我执行以下代码:

db.DBUsers.InsertOnSubmit(new DBUser
    {
        Id = id,
        BrandCode3 = brandCode3.ToLower(),
        LoweredUsername = username.ToLower(),
        Username = username,
        CreationDate = date,
        Salt = salt,
        Password = SecurityService.CreateMD5Hash(salt + password),
        PasswordQuestion = passwordQuestion,
        PasswordAnswer = passwordAnswer,
        Comment = comment,
        Email = email,
        IsApproved = isApproved,
        LastPasswordChangedDate = date,
        FailedPasswordAnswerAttemptCount = 0,
        FailedPasswordAnswerAttemptWindowStart = date,
        IsLockedOut = false,
        IsOnLine = false,
        LastActivityDate = date
    }
);
db.SubmitChanges();

UPDATE UPDATE
Here's the attributes for the primary key: 这是主键的属性:

[Column(Storage="_Id", DbType="UniqueIdentifier NOT NULL", IsPrimaryKey=true)]
public System.Guid Id

I noticed that the Auto-sync property has the value "Never" in the properties window. 我注意到Auto-sync属性在属性窗口中的值为“Never”。 My guess would be this needs to be OnInsert. 我的猜测是需要OnInsert。 Gonna check that. 要检查一下。

Right before I call submitchanges I check the change set and it shows no inserts, updates or deletes... SQL profiler shows me no query is sent, attaching a db.Log shows me no action is executed. 在我调用submitchanges之前,我检查更改集,它显示没有插入,更新或删除... SQL profiler显示我没有发送查询,附加db.Log显示我没有执行任何操作。
Why isn't anything submitted? 为什么没有提交任何内容?

No primary key defined in the L2S model? L2S模型中没有定义主键? Check so at least one column has the "primary key" attribute set to true. 检查以便至少有一列将“主键”属性设置为true。

ObjectTracking可能被禁用吗?

I suggest you post the auto generated Linq annotations for the primary key and your version tracking field, then we might be able to help. 我建议您为主键和版本跟踪字段发布自动生成的Linq注释,然后我们可以提供帮助。 Here are examples from my working entity model. 以下是我的工作实体模型的示例。

[Column(Storage="_Id", AutoSync=AutoSync.OnInsert,
DbType="Int NOT NULL IDENTITY",
IsPrimaryKey=true, IsDbGenerated=true, UpdateCheck=UpdateCheck.Never)]

And the timestamp column: 和时间戳列:

[Column(Storage="_Ts", AutoSync=AutoSync.Always, DbType="rowversion NOT NULL",
CanBeNull=false, IsDbGenerated=true, IsVersion=true, 
UpdateCheck=UpdateCheck.Never)]

public System.Data.Linq.Binary Ts public System.Data.Linq.Binary Ts

There's nothing I can see from the code that would indicate to me a problem. 我从代码中看不出任何可以向我表明问题的东西。 At this point, I would drag and drop a new DBUser object onto your DBML file (rename it DBUser2), execute this code, and watch it work. 此时,我将一个新的DBUser对象拖放到您的DBML文件中(将其重命名为DBUser2),执行此代码并观察它是否正常工作。 Having working code, I would then check for the differences between the two entities. 有了工作代码,我会检查两个实体之间的差异。 This is going to be something non-obvious. 这将是不明显的事情。 Also, click "Run Custom Tool" on your DBML file and watch your Errors/Warnings window for any warnings -- SqlMetal might just tell you what's wrong in the form of a warning. 此外,单击DBML文件上的“运行自定义工具”并查看“错误/警告”窗口以获取任何警告 - SqlMetal可能只是以警告的形式告诉您出错了什么。

If your Guid Id column is being generated by the database, then this is a bug in Linq To Sql, as documented here , because your property name is different than your column name. 如果由数据库生成的的Guid ID列,那么这是Linq中的一个bug to SQL中,作为记录在这里 ,因为你的属性名称是比你的列名不同。

From your example, it looks like you're assigning it in your application, so it may not apply. 从您的示例中,您似乎在应用程序中分配它,因此它可能不适用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM