Giter Site home page Giter Site logo

gsoster / csharplab Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 49.71 MB

A repository to store my C# code and annotations

C# 74.88% HTML 18.86% CSS 0.26% JavaScript 5.24% Gherkin 0.68% ASP.NET 0.08%
asp-net aspnet-mvc aspnet-web-api c-sharp csharp entity-framework game-development windows-forms

csharplab's Introduction

Hi there πŸ‘‹

Gmail Badge Linkedin Badge Github Badge

Software Engineer @ThoughtWorks. C# Mage. Working with distributed event-based financial systems. I use my programming powers to create universes from blank lines.

Github stats Top Langs

csharplab's People

Contributors

dependabot[bot] avatar gsoster avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

csharplab's Issues

[PhotoGallery] Expanded Image window

Doubleclick in a picture should open a new window with the image.
It should be possible to navigate to the next picture in the collection/folder through the forward and back arrow.

EntityFramework Annotations

Data Annotations

Defining a key to a table in a Model (User Model):

using System.ComponentModel.DataAnnotations;
public class User 
{ 
    [Key] 
    public string Username { get; set; } 
    public string DisplayName { get; set; } 
}

The full list of annotations supported by EF is:
KeyAttribute
StringLengthAttribute
MaxLengthAttribute
ConcurrencyCheckAttribute
RequiredAttribute
TimestampAttribute
ComplexTypeAttribute
ColumnAttribute
TableAttribute
InversePropertyAttribute
ForeignKeyAttribute
DatabaseGeneratedAttribute
NotMappedAttribute


Fluent API

The fluent API is a more advanced way of specifying model configuration that covers everything that data annotations can do in addition to some more advanced configuration not possible with data annotations. Data annotations and the fluent API can be used together.

Let’s say we wanted to rename the column that User.DisplayName is stored in to display_name.:

public class BloggingContext : DbContext 
{ 
    public DbSet<Blog> Blogs { get; set; } 
    public DbSet<Post> Posts { get; set; } 
    public DbSet<User> Users { get; set; } 
 
    protected override void OnModelCreating(DbModelBuilder modelBuilder) 
    { 
        modelBuilder.Entity<User>() 
            .Property(u => u.DisplayName) 
            .HasColumnName("display_name"); 
    } 
}

DbContext

Usually we will craete a derived context, which represents a session with the database, allowing us to query and save data.

using System.Data.Entity;
public class BloggingContext : DbContext 
{ 
    public DbSet<Blog> Blogs { get; set; } 
    public DbSet<Post> Posts { get; set; } 
}

Difference between context.add and attach

Add is for adding newly created objects that do not exist in the database.
Attach is for entities that already exist in the database. ( "when you use Attach you tell the context that the entity is already in the database, SaveChanges will have no effect over attached entities." as described here)
More info can be found in this article by Microsoft: Entity Framework Add and Attach and Entity States.

Asp.net MVC - Razor

To allow only logged on users to see some action:

@if (Request.IsAuthenticated)
   {
      //action
   }

C Sharp jump start annotations

What is an assemply?

  • An assembly is a container for a set of resources and types.
  • Assemblies can be referenced by other Assemblies
  • Some assemblies are specific to certain technologies
  • In visual studio, an assembly equates to a Project

Assemblies can be "Strongly named" with means signed.

Assembly X Namespaces

Assembly (it is a physical, it is a file!):

  • an assembly is a grouping or physical container of code
  • Can contain one or more namespace
  • Can be granted security permissions
  • Can be digitally signed
  • Defines a scope

Namespace (it is logical!):

  • A namespace is a grouping or logical container of code
  • Can span multiple files
  • Can span multiple assemblies
  • Defines a scope

What is Instrumentation? (It is like web analytics for code)

  • Instrumentation is code that reports performance information
  • Telemetry aggregates instrumentation for analysis
  • Diagnostics or Analysis is the use of telemetry to track causes of errors or identify trends

What are Web Services?

  • Web Services encapsulate implementation
  • Web Services expose to disparate system
  • Web Services allow client systems to communicate servers
    • Web protocols (HTTP, GET, POST, etc)
  • Web Services are importante to Service Oriented Architecture
    • With and without metadata
    • Loose coupling

What is SOAP?

  • SOAP is a standard for returning structured data from a Web Services as XML
    • Envelop
      • Header
      • Body
  • SOAP handling is a built-in feature of Visual Studio

What is REST? (Representative State Transfer)

  • REST is becoming a common, industry standard
  • REST does not require XML parsing
  • REST does not require a message header
  • REST is generally human-readable
  • REST uses less bandwidth than SOAP
  • REST services typically return XML or JSON
  • REST JSON is Javascript Object Notation
    • JSON is becoming a common, industry standard
    • JSON is generally a lighter payload than XML (or SOAP)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.