Socket cannot handle large database model with EF6 / MVC5

I have been provided with a database for which basic CRUD operations should be possible. This was quickly achieved with .NET 4.5 / MVC5 and EF6. This means a Database First approach.

New requirement: (Elastic) search.

When creating an index for a custom class (not related to others in the model), everything is fine. When I use a class with a lot of foreign keys, everything stops working. The database consists of 100 tables with 400 + foreign keys.

I think that the problem can be a circular link (the Client has n Contracts in which there is a link to the client who has the list of Contracts ... you get the picture). In the end, I get an OutOfMemory exception and everything crashes.

the code:

public static Uri node;
public static ConnectionSettings settings;
public static ElasticClient client;

public ActionResult TestIndex()
    {
        node = new Uri("http://localhost:9200");
        settings = new ConnectionSettings(node, defaultIndex: "crudapp");
        client = new ElasticClient(settings);

        var indexSettings = new IndexSettings();
        indexSettings.NumberOfReplicas = 1;
        indexSettings.NumberOfShards = 1;

        //The next line causes the OutOfMemoryException
        client.CreateIndex(c => c.Index("crudapp")
                                 .InitializeUsing(indexSettings)
                                 .AddMapping<Customer>(map => map.MapFromAttributes(maxRecursion: 1)));


        foreach (Customer c in db.Customer.Where(a => a.Active == true))
            client.Index(c);

        return View("Index");
    }

Nest, ?

:

    public partial class Customer
    {
        public Customer()
        {
            this.CustomerContract = new HashSet<CustomerContract>();
        }

        public int Customerid { get; set; }
        public string CustomerName { get; set; }
        public string Description { get; set; }
        public bool Active { get; set; }

        public virtual ICollection<CustomerContract> CustomerContract { get; set; }
    }

    public partial class CustomerContract
    {
        public CustomerContract()
        {
            this.Host = new HashSet<Host>();
        }

        public int CustomerContractid { get; set; }
        public string CustomerContractName { get; set; }
        public string Description { get; set; }
        public int CustomerID { get; set; }
        public bool Active { get; set; }

        public virtual Customer Customer { get; set; }
        public virtual ICollection<Host> Host { get; set; }
    }
+4
1

OutOfMemoryException JSON Customer. , NEST Elasticsearch, JSON.NET.

:

1.

JSON.NET . JsonIgnoreAttribute , . IContractResolver EF ( , ) , NEST JSON.NET.

NEST JSON.NET, " ", Elasticsearch.NET NEST (, , -top Elasticsearch.NET). ElasticClient.Index(..) ElasticClient.Raw.Index(..), body JSON ( ) , .

2.

Customer , , (DTO), / Elasticsearch.

foreach (Customer c in db.Customer.Where(a => a.Active == true))
    client.Index(new MyElasticsearchTypes.Customer()
        {
            CustomerId = c.CustomerId,
            CustomerName = c.CustomerName,
            Description = c.Description
        });

# , DTO, :

, Elasticsearch - , "". "" , , , . elasticsearch Data In, Data Out - . Elasticsearch :

, Elasticsearch - , . ,

+2

All Articles