为什么我不能插入带有外键记录在一台服务器的请求?一台、服务器

由网友(纠缠\只会伤害彼此)分享简介:我tryring做外键一个简单的插入,但似乎我需要使用 db.SaveChanges()每一个记录插入。如何管理使用只有一个 db.SaveChanges()在这个程序结束?I'm tryring to do a simple insert with foreign key, but it seems that I...

我tryring做外键一个简单的插入,但似乎我需要使用 db.SaveChanges()每一个记录插入。如何管理使用只有一个 db.SaveChanges()在这个程序结束?

I'm tryring to do a simple insert with foreign key, but it seems that I need to use db.SaveChanges() for every record insert. How can I manage to use only one db.SaveChanges() at the end of this program?

public static void Test()
{
    using (var entities = new DBEntities())
    {
        var sale =
            new SalesFeed
            {
                SaleName = "Stuff...",
            };
        entities.AddToSalesFeedSet(sale);

        var phone =
            new CustomerPhone
            {
                CreationDate = DateTime.UtcNow,
                sales_feeds = sale
            };
        entities.AddToCustomerPhoneSet(phone);

        entities.SaveChanges();
    }
}

运行上面的code之后,我得到这个异​​常:

After running the above code I get this exception:

System.Data.UpdateException:更新条目时发生错误。见的InnerException了解详细信息。指定的值不是有​​效的常数型的一个实例 参数名称:值的

System.Data.UpdateException: An error occurred while updating the entries. See the InnerException for details. The specified value is not an instance of a valid constant type Parameter name: value.

编辑:更改例如code,并添加返回异常

Changed example code and added returned exception.

推荐答案

Apperantly使用 UNSIGNED BIGINT 导致此问题。当我切换到符号的BIGINT 一切正常,因为它应该。

Apperantly using UNSIGNED BIGINT causes this problem. When I switched to SIGNED BIGINT everything worked as it supposed to.

阅读全文

相关推荐

最新文章