本文整理汇总了C#中BrightstarDB.Tests.EntityFramework.MyEntityContext类的典型用法代码示例。如果您正苦于以下问题:C# MyEntityContext类的具体用法?C# MyEntityContext怎么用?C# MyEntityContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MyEntityContext类属于BrightstarDB.Tests.EntityFramework命名空间,在下文中一共展示了MyEntityContext类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: TestCreateAndRetrieve
public void TestCreateAndRetrieve()
{
string storeName = Guid.NewGuid().ToString();
string personId;
using (var dataObjectStore = _dataObjectContext.CreateStore(storeName))
{
using (var context = new MyEntityContext(dataObjectStore))
{
var person = context.Persons.Create();
Assert.IsNotNull(person);
context.SaveChanges();
Assert.IsNotNull(person.Id);
personId = person.Id;
}
}
using (var dataObjectStore = _dataObjectContext.OpenStore(storeName))
{
using (var context = new MyEntityContext(dataObjectStore))
{
var person = context.Persons.FirstOrDefault(p => p.Id == personId);
Assert.IsNotNull(person);
}
}
}
开发者ID:kowalot,项目名称:BrightstarDB,代码行数:25,代码来源:SimpleContextTests.cs
示例2: TestLinqCount
public void TestLinqCount()
{
var connectionString = GetConnectionString("TestLinqCount");
var context = new MyEntityContext(connectionString);
for(var i = 0; i<100; i++)
{
var entity = context.TestEntities.Create();
entity.SomeString = "Entity " + i;
entity.SomeInt = i;
}
context.SaveChanges();
var count = context.TestEntities.Count();
Assert.IsNotNull(count);
Assert.AreEqual(100, count);
for (var j = 0; j < 100; j++)
{
var entity = context.TestEntities.Create();
entity.SomeString = "Entity " + j;
entity.SomeInt = j;
}
context.SaveChanges();
var count2 = context.TestEntities.Count();
Assert.IsNotNull(count2);
Assert.AreEqual(200, count2);
}
开发者ID:jaensen,项目名称:BrightstarDB,代码行数:30,代码来源:LinqTests.cs
示例3: TestSavingCallbackCalled
public void TestSavingCallbackCalled()
{
var context = new MyEntityContext(_connectionString);
_changedItems.Clear();
context.SavingChanges += LogChangedItems;
var alice = new Person {Name = "Alice"};
context.Persons.Add(alice);
var bob = context.Persons.Create();
bob.Name = "Bob";
context.SaveChanges();
Assert.AreEqual(2, _changedItems.Count);
Assert.IsTrue(_changedItems.Cast<Person>().Any(p=>p.Id.Equals(alice.Id)));
Assert.IsTrue(_changedItems.Cast<Person>().Any(p=>p.Id.Equals(bob.Id)));
_changedItems.Clear();
bob.Friends.Add(alice);
context.SaveChanges();
Assert.AreEqual(1, _changedItems.Count);
Assert.IsTrue(_changedItems.Cast<Person>().Any(p => p.Id.Equals(bob.Id)));
_changedItems.Clear();
var skill = new Skill {Name = "Programming"};
context.Skills.Add(skill);
context.SaveChanges();
_changedItems.Clear();
skill.SkilledPeople.Add(bob);
context.SaveChanges();
Assert.AreEqual(1, _changedItems.Count);
Assert.IsTrue(_changedItems.Cast<Person>().Any(p => p.Id.Equals(bob.Id)));
_changedItems.Clear();
}
开发者ID:Garwin4j,项目名称:BrightstarDB,代码行数:35,代码来源:ContextCallbackTests.cs
示例4: TestUseDerivedInstanceInBaseClassCollectionProperty
public void TestUseDerivedInstanceInBaseClassCollectionProperty()
{
var storeName = MakeStoreName("useDerivedInstance");
var context = new MyEntityContext(ConnectionString + storeName);
var entity1 = context.DerivedEntities.Create();
entity1.BaseStringValue = "Entity1";
var entity2 = context.DerivedEntities.Create();
entity2.BaseStringValue = "Entity2";
var entity3 = context.BaseEntities.Create();
entity3.BaseStringValue = "Entity3";
entity1.RelatedEntities.Add(entity2);
entity1.RelatedEntities.Add(entity3);
context.SaveChanges();
context=new MyEntityContext(ConnectionString + storeName);
var baseEntities = context.BaseEntities.ToList();
Assert.AreEqual(3, baseEntities.Count);
var derivedEntities = context.DerivedEntities.ToList();
Assert.AreEqual(2, derivedEntities.Count);
entity1 = context.DerivedEntities.Where(x => x.BaseStringValue.Equals("Entity1")).FirstOrDefault();
Assert.IsNotNull(entity1);
Assert.AreEqual(2, entity1.RelatedEntities.Count);
Assert.IsTrue(entity1.RelatedEntities.Any(x=>x.BaseStringValue.Equals("Entity2")));
Assert.IsTrue(entity1.RelatedEntities.Any(x=>x.BaseStringValue.Equals("Entity3")));
}
开发者ID:rharrisxtheta,项目名称:BrightstarDB,代码行数:26,代码来源:InterfaceInheritanceTests.cs
示例5: QueryableCollectionsTests
public QueryableCollectionsTests()
{
var connectionString = ConnectionString + "StoreName=SimpleCollectionFilter_" + DateTime.UtcNow.Ticks;
_context = new MyEntityContext(connectionString);
var gardening = _context.Skills.Create();
gardening.Name = "Gardening";
var painting = _context.Skills.Create();
painting.Name = "Painting";
var carpentry = _context.Skills.Create();
carpentry.Name = "Carpentry";
_dept = _context.Departments.Create();
_dept.Name = "Department99";
var andy = _context.Persons.Create();
andy.Name = "Andy";
andy.Skills.Add(gardening);
andy.Skills.Add(painting);
andy.Skills.Add(carpentry);
var arnold = _context.Persons.Create();
arnold.Name = "Arnold";
arnold.Skills.Add(painting);
var bert = _context.Persons.Create();
bert.Name = "Bert";
_dept.Persons.Add(andy);
_dept.Persons.Add(bert);
_context.SaveChanges();
}
开发者ID:Garwin4j,项目名称:BrightstarDB,代码行数:29,代码来源:QueryableCollectionsTests.cs
示例6: TestIssue128CannotSetFloatValueBelow1
public void TestIssue128CannotSetFloatValueBelow1()
{
// Create an entity
var entity = _myEntityContext.TestEntities.Create();
// Set the properties that allow fractional values to values < 1.0
entity.SomeDecimal = 0.14m;
entity.SomeDouble = 0.14;
entity.SomeFloat = 0.14F;
// Persist the changes
_myEntityContext.SaveChanges();
var entityId = entity.Id;
// Create a new context connection so that we don't get a locally cached value from the context
var newContext = new MyEntityContext(_connectionString);
// Retrieve the previously created entity
var checkEntity = newContext.TestEntities.FirstOrDefault(e => e.Id.Equals(entityId));
// Assert that the entity was found and the values we set are set to the values we originally provided
Assert.IsNotNull(checkEntity);
Assert.IsNotNull(checkEntity.SomeDecimal);
Assert.IsNotNull(checkEntity.SomeDouble);
Assert.IsNotNull(checkEntity.SomeFloat);
Assert.AreEqual(0.14m, checkEntity.SomeDecimal);
Assert.AreEqual(0.14, checkEntity.SomeDouble);
Assert.AreEqual(0.14F, checkEntity.SomeFloat);
}
开发者ID:jaensen,项目名称:BrightstarDB,代码行数:26,代码来源:DataTypeTests.cs
示例7: TestSetAndGetSimpleProperty
public void TestSetAndGetSimpleProperty()
{
string storeName = Guid.NewGuid().ToString();
var dataObjectStore = _dataObjectContext.CreateStore(storeName);
var context = new MyEntityContext(dataObjectStore);
var person = context.Persons.Create();
Assert.IsNotNull(person);
person.Name = "Kal";
context.SaveChanges();
var personId = person.Id;
// Test that the property is still there when we retrieve the object again
dataObjectStore = _dataObjectContext.OpenStore(storeName);
context = new MyEntityContext(dataObjectStore);
person = context.Persons.Where(p => p.Id == personId).FirstOrDefault();
Assert.IsNotNull(person);
Assert.IsNotNull(person.Name, "person.Name was NULL when retrieved back from server");
Assert.AreEqual("Kal", person.Name, "Unexpected Name property value");
// Test we can also use the simple property in a LINQ query
dataObjectStore = _dataObjectContext.OpenStore(storeName);
context = new MyEntityContext(dataObjectStore);
person = context.Persons.Where(p => p.Name == "Kal").FirstOrDefault();
Assert.IsNotNull(person, "Could not find person by Name");
Assert.AreEqual(personId, person.Id, "Query for person by name returned an unexpected person entity");
// Test we can use ToList()
var people = context.Persons.Where(p => p.Name == "Kal").ToList();
Assert.IsNotNull(people);
Assert.AreEqual(1, people.Count);
Assert.AreEqual(personId, people[0].Id);
}
开发者ID:Garwin4j,项目名称:BrightstarDB,代码行数:32,代码来源:SimpleContextTests.cs
示例8: TestMapToRdfDataTypeDate
public void TestMapToRdfDataTypeDate()
{
var storeName = "foaf_" + Guid.NewGuid().ToString();
var embeddedClient =
BrightstarService.GetClient("type=embedded;storesDirectory=c:\\brightstar;");
embeddedClient.CreateStore(storeName);
//add rdf data for a person
var triples = new StringBuilder();
triples.AppendLine(@"<http://www.networkedplanet.com/people/j.williams> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://xmlns.com/foaf/0.1/Person> .");
triples.AppendLine(@"<http://www.networkedplanet.com/people/j.williams> <http://xmlns.com/foaf/0.1/name> ""Jen Williams"" .");
triples.AppendLine(@"<http://www.networkedplanet.com/people/j.williams> <http://dbpedia.org/ontology/birthDate> ""1921-11-28""^^<http://www.w3.org/2001/XMLSchema#date> .");
embeddedClient.ExecuteTransaction(storeName, null, null, triples.ToString());
//check EF can access all properties
var context = new MyEntityContext(string.Format(@"type=embedded;storesDirectory=c:\\brightstar;storeName={0}", storeName));
Assert.IsNotNull(context.FoafPersons);
Assert.AreEqual(1, context.FoafPersons.Count());
var person = context.FoafPersons.FirstOrDefault();
Assert.IsNotNull(person);
Assert.IsNotNull(person.Id);
Assert.AreEqual("j.williams", person.Id);
Assert.IsNotNull(person.Name);
Assert.AreEqual("Jen Williams", person.Name);
Assert.IsNotNull(person.BirthDate);
}
开发者ID:phatcher,项目名称:BrightstarDB,代码行数:30,代码来源:EFClientTests.cs
示例9: TestSavingChangesUpdatesTimestamp
public void TestSavingChangesUpdatesTimestamp()
{
IArticle article;
DateTime saving, updating;
using (var context = new MyEntityContext(_connectionString))
{
context.SavingChanges += UpdateTrackable;
article = context.Articles.Create();
article.Title = "My Test Article";
saving = DateTime.Now;
context.SaveChanges();
}
using (var context = new MyEntityContext(_connectionString))
{
context.SavingChanges += UpdateTrackable;
article = context.Articles.FirstOrDefault(a => a.Id.Equals(article.Id));
Assert.IsNotNull(article);
Assert.IsTrue(article.Created >= saving);
Assert.IsTrue(article.LastModified >= saving);
article.BodyText = "Some body text";
updating = DateTime.Now;
context.SaveChanges();
}
using (var context = new MyEntityContext(_connectionString))
{
article = context.Articles.FirstOrDefault(a => a.Id.Equals(article.Id));
Assert.IsNotNull(article);
Assert.IsTrue(article.Created >= saving);
Assert.IsTrue(article.LastModified >= updating);
}
}
开发者ID:rharrisxtheta,项目名称:BrightstarDB,代码行数:31,代码来源:ContextCallbackTests.cs
示例10: TestInsertIntoDefaultGraph
public void TestInsertIntoDefaultGraph()
{
var storeName = "http://www.brightstardb.com/tests#empty";
var connectionString = MakeStoreConnectionString(storeName);
var dataObjectContext = BrightstarService.GetDataObjectContext(connectionString);
string aliceId;
using (var store = dataObjectContext.OpenStore(storeName))
{
using (var context = new MyEntityContext(store))
{
var alice = context.FoafPersons.Create();
aliceId = alice.Id;
context.SaveChanges();
}
}
using (var store = dataObjectContext.OpenStore(storeName))
{
using (var context = new MyEntityContext(store))
{
var alice = context.FoafPersons.FirstOrDefault(p => p.Id.Equals(aliceId));
Assert.That(alice, Is.Not.Null);
}
}
}
开发者ID:jaensen,项目名称:BrightstarDB,代码行数:25,代码来源:DotNetRdfContextTests.cs
示例11: TestAddToInverse
public void TestAddToInverse()
{
string productionId, performanceId;
using (var context = new MyEntityContext(_connectionString))
{
var production = context.Productions.Create();
var performance = context.Performances.Create();
Assert.That(production.Performances.Count, Is.EqualTo(0));
Assert.That(production.Photos.Count, Is.EqualTo(0));
Assert.That(production.ProductionTeam.Count, Is.EqualTo(0));
// Add the performance to the production's perfomances collection
production.Performances.Add(performance);
Assert.That(production.Performances.Count, Is.EqualTo(1));
Assert.That(production.Photos.Count, Is.EqualTo(0));
Assert.That(production.ProductionTeam.Count, Is.EqualTo(0));
context.SaveChanges();
productionId = production.Id;
performanceId = performance.Id;
}
using (var context = new MyEntityContext(_connectionString))
{
var production = context.Productions.FirstOrDefault(x => x.Id.Equals(productionId));
Assert.That(production, Is.Not.Null);
Assert.That(production.Performances.Count, Is.EqualTo(1));
Assert.That(production.Performances.First().Id, Is.EqualTo(performanceId));
Assert.That(production.Photos.Count, Is.EqualTo(0));
Assert.That(production.ProductionTeam.Count, Is.EqualTo(0));
}
}
开发者ID:GTuritto,项目名称:BrightstarDB,代码行数:32,代码来源:InversePropertyTests.cs
示例12: TestLinqCount
public void TestLinqCount()
{
var connectionString = _connectionString + "StoreName=" + Guid.NewGuid();
var context = new MyEntityContext(connectionString);
for(var i = 0; i<100; i++)
{
var entity = context.Entities.Create();
entity.SomeString = "Entity " + i;
entity.SomeInt = i;
}
context.SaveChanges();
var context2 = new MyEntityContext(connectionString);
var count = context2.Entities.Count();
Assert.IsNotNull(count);
Assert.AreEqual(100, count);
for (var j = 0; j < 100; j++)
{
var entity = context2.Entities.Create();
entity.SomeString = "Entity " + j;
entity.SomeInt = j;
}
context2.SaveChanges();
var context3 = new MyEntityContext(connectionString);
var count2 = context3.Entities.Count();
Assert.IsNotNull(count2);
Assert.AreEqual(200, count2);
}
开发者ID:Garwin4j,项目名称:BrightstarDB,代码行数:32,代码来源:LinqTests.cs
示例13: TestCreatePlainLiteral
public void TestCreatePlainLiteral()
{
var storeName = "PlainLiteralTests_CreatePlainLiteral" + DateTime.Now.Ticks;
using (var dataObjectStore = _dataObjectContext.CreateStore(storeName))
{
string conceptAId;
using (var context = new MyEntityContext(dataObjectStore))
{
var conceptA = context.Concepts.Create();
conceptA.PrefLabel = new []
{
new PlainLiteral("Default value"),
new PlainLiteral("English value", "en"),
new PlainLiteral("US English value", "en-US"),
};
context.SaveChanges();
conceptAId = conceptA.Id;
}
using (var context = new MyEntityContext(dataObjectStore))
{
var conceptA = context.Concepts.FirstOrDefault(c => c.Id.Equals(conceptAId));
Assert.IsNotNull(conceptA);
Assert.That(conceptA.PrefLabel.Count, Is.EqualTo(3));
Assert.That(conceptA.PrefLabel.Any(l=>l.Value.Equals("Default value") && l.Language.Equals(String.Empty)));
Assert.That(conceptA.PrefLabel.Any(l=>l.Value.Equals("English value") && l.Language.Equals("en")));
Assert.That(conceptA.PrefLabel.Any(l=>l.Value.Equals("US English value") && l.Language.Equals("en-us")));
}
}
}
开发者ID:GTuritto,项目名称:BrightstarDB,代码行数:29,代码来源:PlainLiteralTests.cs
示例14: SetUp
public void SetUp()
{
_context = new MyEntityContext("type=embedded;storesDirectory=" + Configuration.StoreLocation + ";storeName=EFStringComparisonTests_" + DateTime.Now.Ticks);
var np = new Company {Name = "NetworkedPlanet"};
var apple = new Company {Name = "Apple"};
_context.Companies.Add(np);
_context.Companies.Add(apple);
_context.SaveChanges();
}
开发者ID:stangelandcl,项目名称:BrightstarDB,代码行数:9,代码来源:StringComparisonTests.cs
示例15: TestSaveWorksWhenNoCallback
public void TestSaveWorksWhenNoCallback()
{
var context = new MyEntityContext(_connectionString);
var carol = new Person { Name = "Carol" };
context.Persons.Add(carol);
context.SaveChanges();
var found = context.Persons.FirstOrDefault(p => p.Name.Equals("Carol"));
Assert.IsNotNull(found);
}
开发者ID:Garwin4j,项目名称:BrightstarDB,代码行数:10,代码来源:ContextCallbackTests.cs
示例16: TestCannotCreateEntityWithKey
public void TestCannotCreateEntityWithKey()
{
string storeName = "CannotCreateEntityWithKey_" + DateTime.UtcNow.Ticks;
using (var dataObjectStore = _dataObjectContext.CreateStore(storeName))
{
using (var context = new MyEntityContext(dataObjectStore))
{
// Should throw an exception as the Name property is required to generate the key
context.StringKeyEntities.Create();
context.SaveChanges();
}
}
}
开发者ID:GTuritto,项目名称:BrightstarDB,代码行数:13,代码来源:SimpleContextTests.cs
示例17: PropertyChangeNotificationTests
public PropertyChangeNotificationTests()
{
_storeName = "PropertyChangeNotificationTests_" + DateTime.UtcNow.Ticks;
_context = new MyEntityContext("type=embedded;storesDirectory=c:\\brightstar;storeName="+_storeName);
_ftse = _context.Markets.Create();
_nyse = _context.Markets.Create();
_company = _context.Companies.Create();
_company.Name = "Glaxo";
_company.HeadCount = 20000;
_company.PropertyChanged += HandlePropertyChanged;
_person = _context.FoafPersons.Create();
(_person.MboxSums as INotifyCollectionChanged).CollectionChanged += HandleCollectionChanged;
_context.SaveChanges();
}
开发者ID:Garwin4j,项目名称:BrightstarDB,代码行数:14,代码来源:PropertyChangeNotificationTests.cs
示例18: TestIdentifierPrefixOnBaseEntity
public void TestIdentifierPrefixOnBaseEntity()
{
var storeName = MakeStoreName("IdentifierPrefixOnBaseEntity");
using (var context = new MyEntityContext(ConnectionString + storeName))
{
var entity1 = new DerivedEntity {Id = "entity1"};
context.DerivedEntities.Add(entity1);
entity1.BaseStringValue = "Entity1";
context.SaveChanges();
}
var doContext = BrightstarDB.Client.BrightstarService.GetDataObjectContext(ConnectionString + storeName);
var store = doContext.OpenStore(storeName);
var dataObject = store.GetDataObject("http://example.org/entities/entity1");
Assert.That(dataObject, Is.Not.Null);
}
开发者ID:GTuritto,项目名称:BrightstarDB,代码行数:16,代码来源:InterfaceInheritanceTests.cs
示例19: TestInitializeWithStoreConfiguration
public void TestInitializeWithStoreConfiguration()
{
var configFilePath = Path.GetFullPath(Configuration.DataLocation + "dataObjectStoreConfig.ttl");
var connectionString = "type=dotNetRdf;configuration=" + configFilePath + ";storeName=example;store=http://www.brightstardb.com/tests#peopleStore";
const string baseGraph = "http://example.org/people";
var context = new MyEntityContext(connectionString, updateGraphUri:baseGraph, datasetGraphUris:new string[]{baseGraph});
// Can find by property
var alice = context.FoafPersons.FirstOrDefault(p => p.Name.Equals("Alice"));
Assert.That(alice, Is.Not.Null);
// Can find by ID
alice = context.FoafPersons.FirstOrDefault(p => p.Id.Equals("alice"));
Assert.That(alice, Is.Not.Null);
Assert.That(alice.Name, Is.EqualTo("Alice"));
Assert.That(alice.Knows, Is.Not.Null);
}
开发者ID:rharrisxtheta,项目名称:BrightstarDB,代码行数:16,代码来源:DotNetRdfContextTests.cs
示例20: TestLinqAverage
public void TestLinqAverage()
{
var connectionString = _connectionString + "StoreName=" + Guid.NewGuid();
var context = new MyEntityContext(connectionString);
var e1 = context.Entities.Create();
e1.SomeInt = 10;
e1.SomeDecimal = 10;
e1.SomeDouble = 10;
var e2 = context.Entities.Create();
e2.SomeInt = 12;
e2.SomeDecimal = 12;
e2.SomeDouble = 12;
var e3 = context.Entities.Create();
e3.SomeInt = 15;
e3.SomeDecimal = 15;
e3.SomeDouble = 15;
var e4 = context.Entities.Create();
e4.SomeInt = 10;
e4.SomeDecimal = 10;
e4.SomeDouble = 10;
var e5 = context.Entities.Create();
e5.SomeInt = 11;
e5.SomeDecimal = 11;
e5.SomeDouble = 11;
context.SaveChanges();
Assert.AreEqual(5, context.Entities.Count());
var avInt = context.Entities.Average(e => e.SomeInt);
Assert.IsNotNull(avInt);
Assert.AreEqual(11.6, avInt);
var avDec = context.Entities.Average(e => e.SomeDecimal);
Assert.IsNotNull(avDec);
Assert.AreEqual(11.6m, avDec);
var avDbl = context.Entities.Average(e => e.SomeDouble);
Assert.IsNotNull(avDbl);
Assert.AreEqual(11.6, avDbl);
}
开发者ID:Garwin4j,项目名称:BrightstarDB,代码行数:47,代码来源:LinqTests.cs
注:本文中的BrightstarDB.Tests.EntityFramework.MyEntityContext类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论