Last active
October 7, 2015 13:54
-
-
Save FransBouma/731a7d904630084c4218 to your computer and use it in GitHub Desktop.
EF to RavenDB with almost no work. Still have to tell RavenDB that the field with the Key attribute is the Id field, but that's minor.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[TestFixture] | |
public class SimpleTests | |
{ | |
private IDocumentStore _store; | |
[TestFixtureSetUp] | |
public void Init() | |
{ | |
InterceptorCore.Initialize("EF6"); | |
System.Data.Entity.Database.SetInitializer<NWDocDBDataContext>(null); | |
_store = new DocumentStore() {Url = "http://localhost:8080/", DefaultDatabase = "Northwind"}; | |
_store.Initialize(); | |
} | |
[Test] | |
public void InsertOrders() | |
{ | |
// first fetch them from the DB using EF | |
var ctx = new NWDocDBDataContext(); | |
var alfkiOrders = ctx.Orders.Where(o=>o.Customer.CustomerId == "ALFKI").ProjectToOrderDoc().ToList(); | |
// store them into the doc db | |
using(var session = _store.OpenSession()) | |
{ | |
foreach(var d in alfkiOrders) | |
{ | |
session.Store(d); | |
} | |
session.SaveChanges(); | |
} | |
} | |
[TestFixtureTearDown] | |
public void Shutdown() | |
{ | |
_store.Dispose(); | |
} | |
} |
Author
FransBouma
commented
Oct 7, 2015
//------------------------------------------------------------------------------
// <auto-generated>This code was generated by LLBLGen Pro v5.0.</auto-generated>
//------------------------------------------------------------------------------
using System;
using System.ComponentModel;
using System.Runtime.Serialization;
using System.Xml.Serialization;
using System.Collections.Specialized;
using System.Collections.Generic;
namespace Documents.DocumentClasses
{
/// <summary> Document class which is derived from the entity 'Order'.</summary>
public class OrderDoc
{
/// <summary>Gets or sets the CompanyName field. Derived from Entity Model Field 'Customer.CompanyName (Customer)'</summary>
public System.String CompanyName { get; set; }
/// <summary>Gets or sets the ContactName field. Derived from Entity Model Field 'Customer.ContactName (Customer)'</summary>
public System.String ContactName { get; set; }
/// <summary>Gets or sets the CustomerId field. Derived from Entity Model Field 'Customer.CustomerId (Customer)'</summary>
public System.String CustomerId { get; set; }
/// <summary>Gets or sets the OrderDate field. Derived from Entity Model Field 'Order.OrderDate'</summary>
public Nullable<System.DateTime> OrderDate { get; set; }
/// <summary>Gets or sets the OrderId field. Derived from Entity Model Field 'Order.OrderId'</summary>
[System.ComponentModel.DataAnnotations.Key]
public System.Int32 OrderId { get; set; }
/// <summary>Gets or sets the RequiredDate field. Derived from Entity Model Field 'Order.RequiredDate'</summary>
public Nullable<System.DateTime> RequiredDate { get; set; }
}
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment