小编Fal*_*ick的帖子

当我没有为标识列指定值时,为什么我在LINQ to SQL中获得"无法为标识列插入显式值"?

我有一个看起来像这样的表: 替代文字

ClientID是我在表中唯一的标识列.UserID是不同表主键的FK.

这是我的Linq to SQL插入代码:

public void InsertClientByUsername(string username, Entities.Client clientInfo)
{

    using (LinqModelDataContext db = new LinqModelDataContext())
    {

        var existingClient = (from client in db.Clients
                              join ext_usr in db.User_Extendeds on client.UserID equals ext_usr.FriendlyUserID
                              join asp_usr in db.aspnet_Users on ext_usr.UserID equals asp_usr.UserId
                              where asp_usr.UserName.ToLower().Equals(username)
                              select client).SingleOrDefault();

        if (existingClient != null)
        {
            existingClient.Address1 = clientInfo.Address1;
            existingClient.Address2 = clientInfo.Address2;
            existingClient.City = clientInfo.City;
            existingClient.CompanyName = clientInfo.CompanyName;
            existingClient.CountryID = clientInfo.CountryID;
            existingClient.FaxNumber = clientInfo.Fax;
            existingClient.FirstName = clientInfo.FirstName;
            existingClient.LastName = clientInfo.LastName;
            existingClient.MailingAttention = clientInfo.Attention;
            existingClient.PhoneNumber = …
Run Code Online (Sandbox Code Playgroud)

c# linq-to-sql

5
推荐指数
1
解决办法
1万
查看次数

标签 统计

c# ×1

linq-to-sql ×1