View 2015-07-24-how-to-automatically-load-navigation-properties-in-entity-framework_003.cs
public virtual IQueryable<TEntity> FindAll(Expression<Func<TEntity, bool>> where = null)
{
IQueryable<TEntity> query = where == null ? this.Context.Set <TEntity> () : this.Context.Set<TEntity>().Where(where);
var workspace = ((IObjectContextAdapter)this.Context).ObjectContext.MetadataWorkspace;
var itemCollection = (ObjectItemCollection)(workspace.GetItemCollection(DataSpace.OSpace));
var entityType = itemCollection.OfType<EntityType>().FirstOrDefault(e => itemCollection.GetClrType(e) == typeof(TEntity));
if (entityType != null)
{
View 2015-07-24-how-to-automatically-load-navigation-properties-in-entity-framework_001.cs
public class Blog
{
public int BlogId { get; set; }
public string Name { get; set; }
public string Url { get; set; }
public string Tags { get; set; }
public ICollection<Post> Posts { get; set; }
}
View 2015-05-05-c-and-the-wordpress-api_002.cs
public static string CharacterLimit(this string text, int length)
{
if (text.Length <= length) return text;
int pos = text.IndexOf(" ", length);
if (pos >= 0) return text.Substring(0, pos) + "...";
return text;
}
View 2015-05-26-developing-real-time-applications-with-signalr-and-sqldependency-in-asp-net-mvc-and-c_004.cs
public JsonResult GetMessages()
{
using(FleetContext ctx = new FleetContext())
{
IEnumerable<string> messages = ctx.Insurers.AsQueryable().Cast<Insurer>().Select(x => x.Name).ToList();
var dataOutput = Json(messages, JsonRequestBehavior.AllowGet);
return dataOutput;
}
}
View 2015-05-26-developing-real-time-applications-with-signalr-and-sqldependency-in-asp-net-mvc-and-c_003.cshtml
<div class="row">
<div class="col-md-12">
<div id="messagesTable">
</div>
</div>
</div>
@section scripts
{
<script src="~/Scripts/jquery.signalR-2.2.0.min.js"></script>
View 2015-05-26-developing-real-time-applications-with-signalr-and-sqldependency-in-asp-net-mvc-and-c_002.cs
using Microsoft.AspNet.SignalR;
using Microsoft.AspNet.SignalR.Hubs;
public class ChatHub : Hub
{
[HubMethodName(&quot;sendMessages&quot;)]
public static void SendMessages()
{
IHubContext context = GlobalHost.ConnectionManager.GetHubContext&lt;ChatHub&gt;();
context.Clients.All.updateMessages();
View 2015-05-26-developing-real-time-applications-with-signalr-and-sqldependency-in-asp-net-mvc-and-c_001.cs
string connectionString = Settings.Default.ConnString;
string listenQuery = @ & quot;
SELECT[Name] FROM[dbo].[Insurers] & quot;;
// Create instance of the DB Listener
DatabaseChangeListener changeListener = new DatabaseChangeListener(connectionString);
// Define what to do when changes were detected
changeListener.OnChange += () =>
{
View 2015-05-05-c-and-the-wordpress-api_001.cs
public IEnumerable GetWordPressPosts()
{
using(WebClient webClient = new WebClient())
{
string blogUrl = @ "https://public-api.wordpress.com/rest/v1.1/sites/hendrikbulens.wordpress.com/posts/";
string response = webClient.DownloadString(blogUrl);
WordPressBlog blogPosts = JsonConvert.DeserializeObject(response);
IEnumerable posts = blogPosts.posts.OrderByDescending(x => x.date).Take(3).Select(x => new BlogPost() {
Title = x.title,