public void Projecting2() { ActiveRecordStarter.Initialize(GetConfigSource(), typeof(Widget)); Recreate(); Widget.DeleteAll(); var widget = new Widget { Name = "foo" }; widget.Save(); var orderedQueryable = ActiveRecordLinqBase<Widget>.Queryable; var name = (from w in orderedQueryable where w.Name.StartsWith("f") select w.Name).First(); Assert.IsNotNull(name); Assert.AreEqual("foo", name); }
public void UsingLinqViaSessionScopeVariable() { ActiveRecordStarter.Initialize(GetConfigSource(), typeof(Widget)); using (ISessionScope scope = new SessionScope()) { Recreate(); Widget.DeleteAll(); var widgets = from w in scope.AsQueryable<Widget>() select w; Assert.IsNotNull(widgets); Assert.AreEqual(0, widgets.Count()); Widget widget = new Widget { Name = "Hello world" }; widget.Save(); widgets = from w in scope.AsQueryable<Widget>() where w.Name == "Hello World" select w; Assert.IsNotNull(widgets); Assert.AreEqual(1, widgets.Count()); } }
public void Linq_without_session_scope2() { ActiveRecordStarter.Initialize(GetConfigSource(), typeof(Widget)); Recreate(); Widget.DeleteAll(); var widget = new Widget { Name = "foo" }; widget.Save(); var orderedQueryable = ActiveRecordLinqBase<Widget>.Queryable; var widgets = (from w in orderedQueryable where w.Name.StartsWith("f") select w).ToList(); Assert.IsNotNull(widgets); Assert.AreEqual("foo", widgets.Single().Name); }
public void UsingLinqFromNonLinqBaseClass() { ActiveRecordStarter.Initialize(GetConfigSource(), typeof(Widget)); Recreate(); Widget.DeleteAll(); Widget widget0 = new Widget { Name = "Hello world" }; widget0.Save(); using (new SessionScope()) { var widgets = from w in ActiveRecordLinq.AsQueryable<Widget>() select w; Assert.IsNotNull(widgets); Assert.AreEqual(1, widgets.Count()); var widget = (from w in ActiveRecordLinq.AsQueryable<Widget>() select w).First(); Assert.IsNotNull(widget); Assert.AreEqual("Hello world", widget.Name); var widget2 = ActiveRecordLinq.AsQueryable<Widget>().First(w => w.Name == "Hello World"); Assert.IsNotNull(widget2); Assert.AreEqual("Hello world", widget2.Name); Assert.AreSame(widget2, widget); } }