用于ORM的EF BulkInsert() [英] EF BulkInsert() for ORM

查看:45
本文介绍了用于ORM的EF BulkInsert()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 

在我们的应用程序中,我们有Invoice和InvoiceItem类,如下所示:

In our application we have Invoice and InvoiceItem classes like below:

   公共类发票

    {

        [Key]

  &NBSP; &NBSP; &NBSP; public int InvoiceId {get;组; }¥b $ b  &NBSP; &NBSP; &NBSP; public string InvoiceNumber {get;组; }¥b $ b  &NBSP; &NBSP; &NBSP; public DateTime InvoiceDate {get;组; }¥b $ b  &NBSP; &NBSP; &NBSP;公共列表< InvoiceItem> InvoiceItems {get;组; }¥b $ b  &NBSP; }

    public class Invoice
    {
        [Key]
        public int InvoiceId { get; set; }
        public string InvoiceNumber { get; set; }
        public DateTime InvoiceDate { get; set; }
        public List<InvoiceItem> InvoiceItems { get; set; }
    }

每个Invoice可以有多个InvoiceItem条目,它们通过InvoiceId字段链接。

Each Invoice could have multiple entries of InvoiceItem and they are linked by the InvoiceId field.

这就是我们为Entity Framework设置DBContext的方法。

This is how we set up our DBContext for Entity Framework.

  &NBSP; class AppDbContext:DbContext

  &NBSP; {

  &NBSP; &NBSP; &NBSP; public AppDbContext():base(" DefaultConnection"){}

  &NBSP; &NBSP; &NBSP; public DbSet< Invoice>发票{get;组; }¥b $ b  &NBSP; &NBSP; &NBSP; public DbSet< InvoiceItem> InvoiceItems {get;组; }¥b $ b  &NBSP; }

    class AppDbContext : DbContext
    {
        public AppDbContext() : base("DefaultConnection") { }
        public DbSet<Invoice> Invoices { get; set; }
        public DbSet<InvoiceItem> InvoiceItems { get; set; }
    }

当我们调用SaveChanges()时,两个表都已正确填充,但需要很长时间。我们试图通过使用如下所示的BulkInsert()来提高性能,但只填充了Invoice表。 InvoiceItem表格保持空白。



  &NBSP;使用(AppDbContext dbContext = new AppDbContext())

  &NBSP; {

    dbContext.BulkInsert(new List< Invoicce> {invoice});

  &NBSP; } b $ b

When we call SaveChanges(), both tables were populated properly, but it takes a long time. We are trying to improve the performance by using BulkInsert() like below, but only the Invoice table is populated. The InvoiceItem table stays empty.

    using (AppDbContext dbContext = new AppDbContext())
    {
   dbContext.BulkInsert(new List<Invoicce> { invoice });
    }

我们怎么能解决这个问题呢?

How could we resolve this problem, please?

谢谢,

WY

Thanks,
WY

ywb

推荐答案

你好名字wb,

Hi name wb,

>>我们怎么解决这个问题呢?

据我所知,Entity框架不支持BulkInsert。看来你使用了一些实体框架扩展,由第三方作者编写。我建议你可以联系相关作者寻求合适的支持。

As far as I know, Entity framework does not support BulkInsert. it seems that you use some entity framework extension, which write by 3rd-party author. I would suggest that you could contact related author for suitable support.

感谢你的理解。

祝你好运,

Cole


这篇关于用于ORM的EF BulkInsert()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆