<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>C# &#8211; Stefan Meyer</title>
	<atom:link href="https://blog.meyer-luenen.de/category/programmieren/net/c-sharp/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.meyer-luenen.de</link>
	<description>Lose-Blatt-Sammlung</description>
	<lastBuildDate>Thu, 07 Mar 2024 12:36:01 +0000</lastBuildDate>
	<language>de</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.1</generator>

<image>
	<url>https://i0.wp.com/blog.meyer-luenen.de/wp-content/uploads/2018/12/cropped-StM-Portrait-Raesfeld-600x600-removebg-2.png?fit=32%2C32&#038;ssl=1</url>
	<title>C# &#8211; Stefan Meyer</title>
	<link>https://blog.meyer-luenen.de</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">148105417</site>	<item>
		<title>Visual Studio Code Remote Development</title>
		<link>https://blog.meyer-luenen.de/2024/03/07/visual-studio-code-remote-development/</link>
		
		<dc:creator><![CDATA[Stefan]]></dc:creator>
		<pubDate>Thu, 07 Mar 2024 12:36:01 +0000</pubDate>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Linux / Unix]]></category>
		<guid isPermaLink="false">https://blog.meyer-luenen.de/?p=736</guid>

					<description><![CDATA[Um auf einem Ubuntu-Server das Remote Dedugging zu installieren (Achtung: sollte man nicht auf einen Produktionsserver tun!):]]></description>
										<content:encoded><![CDATA[
<p>Um auf einem Ubuntu-Server das Remote Dedugging zu installieren (Achtung: sollte man nicht auf einen Produktionsserver tun!):</p>



<pre class="wp-block-code"><code>curl -sSL https://aka.ms/getvsdbgsh | bash /dev/stdin -v latest -l ~/.vs-debugger</code></pre>



<p></p>



<p></p>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">736</post-id>	</item>
		<item>
		<title>Login-Seiten für MS-Identity</title>
		<link>https://blog.meyer-luenen.de/2023/12/16/login-seiten-fuer-ms-identity/</link>
		
		<dc:creator><![CDATA[Stefan]]></dc:creator>
		<pubDate>Sat, 16 Dec 2023 15:01:22 +0000</pubDate>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Entity Framework]]></category>
		<guid isPermaLink="false">https://blog.meyer-luenen.de/?p=708</guid>

					<description><![CDATA[aspnet-codegenerator installieren:]]></description>
										<content:encoded><![CDATA[
<p>aspnet-codegenerator installieren:</p>



<pre class="wp-block-code"><code>dotnet tool install -g dotnet-aspnet-codegenerator --version 6.0.0</code></pre>



<p></p>



<pre class="wp-block-code"><code>dotnet aspnet-codegenerator identity -dc ApplicationDbContext<br>oder wenn vorhanden:<br>dotnet aspnet-codegenerator identity -dc ApplicationDbContext --force</code></pre>



<pre class="wp-block-code"><code>dotnet add package Microsoft.VisualStudio.Web.CodeGeneration.Design<br>dotnet add package Microsoft.VisualStudio.Web.CodeGeneration.Design --version 6.0.0</code></pre>



<pre class="wp-block-code"><code>dotnet aspnet-codegenerator identity -dc MyBlazorApp.Data.ApplicationDbContext --files "Account.Register;Account.Login;Account.Logout"


Quelle:
<a href="https://learn.microsoft.com/de-de/aspnet/core/fundamentals/tools/dotnet-aspnet-codegenerator?view=aspnetcore-8.0" target="_blank" rel="noreferrer noopener">https://learn.microsoft.com/de-de/aspnet/core/fundamentals/tools/dotnet-aspnet-codegenerator?view=aspnetcore-8.0
</a>



</code></pre>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">708</post-id>	</item>
		<item>
		<title>EntityFramework.Core in eine .net Core Blazor WebApp integrieren</title>
		<link>https://blog.meyer-luenen.de/2023/09/02/entityframework-core-in-eine-net-core-blazor-webapp-integrieren/</link>
		
		<dc:creator><![CDATA[Stefan]]></dc:creator>
		<pubDate>Sat, 02 Sep 2023 12:20:13 +0000</pubDate>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Allgemein]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Entity Framework]]></category>
		<guid isPermaLink="false">https://blog.meyer-luenen.de/?p=685</guid>

					<description><![CDATA[1. Install necessary packages: For a Blazor Server App, you&#8217;d typically manage the EF Core functionality in the Server project. So, make sure you are working in the Server project directory or set the Server project as the default project in the Package Manager Console (PMC) in Visual Studio. Using the NuGet Package Manager or [&#8230;]]]></description>
										<content:encoded><![CDATA[
<h3 class="wp-block-heading">1. Install necessary packages:</h3>



<p>For a Blazor Server App, you&#8217;d typically manage the EF Core functionality in the Server project. So, make sure you are working in the Server project directory or set the Server project as the default project in the Package Manager Console (PMC) in Visual Studio.</p>



<p>Using the NuGet Package Manager or the PMC, install the following packages:</p>



<ul class="wp-block-list">
<li><code>Microsoft.EntityFrameworkCore</code></li>



<li><code>Microsoft.EntityFrameworkCore.SqlServer</code></li>



<li><code>Microsoft.EntityFrameworkCore.Tools</code> (for migration tools)</li>
</ul>



<h3 class="wp-block-heading">2. Define your Model:</h3>



<p>Create classes that will define the structure of your database tables. Place these in the Shared or Server project, depending on your design decisions.</p>



<p>Example:</p>



<pre class="wp-block-preformatted"><code>public class Product
{
    public int ProductId { get; set; }
    public string Name { get; set; }
    public decimal Price { get; set; }
}
</code></pre>



<h3 class="wp-block-heading">3. Create a DbContext:</h3>



<p>In the Server project, create a class that derives from <code>DbContext</code>:</p>



<pre class="wp-block-preformatted"><code>public class AppDbContext : DbContext
{
    public AppDbContext(DbContextOptions&lt;AppDbContext&gt; options) : base(options) { }

    public DbSet&lt;Product&gt; Products { get; set; }
}
</code></pre>



<h3 class="wp-block-heading">4. Configure the Connection String:</h3>



<p>In the <code>appsettings.json</code> file in the Server project, add your connection string:</p>



<pre class="wp-block-preformatted"><code>{
  "ConnectionStrings": {
    "DefaultConnection": "</code>Server=Servername;Database=DatabaseName;user=UserId;password=secret;MultipleActiveResultSets=true;TrustServerCertificate=True;MultiSubnetFailover=True<code>"
  }
}
</code></pre>



<p>Replace <code>YourConnectionStringHere</code> with your MS SQL Server 2022 connection string.</p>



<h3 class="wp-block-heading">5. Register DbContext:</h3>



<p>In the <code>Startup.cs</code> (or <code>Program.cs</code> for newer versions) of your Server project, register the <code>DbContext</code> in the <code>ConfigureServices</code> method:</p>



<pre class="wp-block-code"><code>builder.<code>Services.AddDbContext&lt;AppDbContext>(options =><br>    options.UseSqlServer(builder.Configuration.GetConnectionString("DefaultConnection")));</code></code></pre>



<p>(Do not forget to import EF Core)</p>



<h3 class="wp-block-heading">6. Create Initial Migration:</h3>



<p>In the PMC or terminal, navigate to the Server project directory and run:</p>



<pre class="wp-block-preformatted"><code>Add-Migration InitialCreate
</code></pre>



<p>This will scaffold a migration to create the initial set of tables for your model.</p>



<h3 class="wp-block-heading">7. Update the Database:</h3>



<p>Apply the migration to create the database schema:</p>



<pre class="wp-block-preformatted"><code>Update-Database
</code></pre>



<pre class="wp-block-preformatted"><code>
</code></pre>



<h3 class="wp-block-heading">8. Use the DbContext in your app:</h3>



<p>Now you can inject and use your <code>DbContext</code> in your pages, components, or services:</p>



<pre class="wp-block-preformatted">csharpCopy code<code>@inject AppDbContext _context

// ...

var products = await _context.Products.ToListAsync();
</code></pre>



<p>That&#8217;s the basic setup! As your app grows, you might add more entities, relationships, migrations, and other advanced EF Core features. Ensure you understand concepts like the lifecycle of a DbContext and how it tracks changes to entities to avoid issues when manipulating data.</p>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">685</post-id>	</item>
		<item>
		<title>appsettings.json erstellen</title>
		<link>https://blog.meyer-luenen.de/2023/04/28/appsettings-json-erstellen/</link>
		
		<dc:creator><![CDATA[Stefan]]></dc:creator>
		<pubDate>Fri, 28 Apr 2023 12:09:14 +0000</pubDate>
				<category><![CDATA[C#]]></category>
		<guid isPermaLink="false">https://blog.meyer-luenen.de/?p=591</guid>

					<description><![CDATA[Installation nuget Packages in V 7.0.0 Neue Datei appsettings.json im root-Verzeichnis erstellen In z.B. Program.cs: Connection String auslesen: Setting auslesen: Verschachtelte Settings auslesen:]]></description>
										<content:encoded><![CDATA[
<p>Installation nuget Packages in V 7.0.0</p>



<pre class="wp-block-code"><code>Microsoft.Extensions.Configuration
Microsoft.Extensions.Configuration.Json</code></pre>



<p>Neue Datei appsettings.json im root-Verzeichnis erstellen</p>



<p>In z.B. Program.cs:</p>



<pre class="wp-block-code"><code>public static IConfiguration _conf;
var configuration = new ConfigurationBuilder()
  .AddJsonFile($"appsettings.json");
_conf = configuration.Build();</code></pre>



<p>Connection String auslesen:</p>



<pre class="wp-block-code"><code>string connectionString = _conf.GetConnectionString("DefaultConnection")!;
</code></pre>



<p>Setting auslesen:</p>



<pre class="wp-block-code"><code>string s = _conf.GetSection("section").Value!;</code></pre>



<p>Verschachtelte Settings auslesen:</p>



<pre class="wp-block-code"><code>"MainSection": {
  "SubSection": {
    "SubSubSection": "value"
}
string s2 = _conf.GetSection("section:SubSection:SubSubSection").Value!;</code></pre>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">591</post-id>	</item>
		<item>
		<title>Sortieren einer Liste</title>
		<link>https://blog.meyer-luenen.de/2022/02/22/sortieren-einer-liste/</link>
		
		<dc:creator><![CDATA[Stefan]]></dc:creator>
		<pubDate>Tue, 22 Feb 2022 14:12:10 +0000</pubDate>
				<category><![CDATA[C#]]></category>
		<guid isPermaLink="false">https://blog.meyer-luenen.de/?p=504</guid>

					<description><![CDATA[]]></description>
										<content:encoded><![CDATA[
<pre class="wp-block-code"><code>ListName = ListName.OrderBy(q => q).ToList();</code></pre>



<p></p>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">504</post-id>	</item>
		<item>
		<title>Merkzettel</title>
		<link>https://blog.meyer-luenen.de/2021/01/30/merkzettel/</link>
		
		<dc:creator><![CDATA[Stefan]]></dc:creator>
		<pubDate>Sat, 30 Jan 2021 07:59:27 +0000</pubDate>
				<category><![CDATA[C#]]></category>
		<guid isPermaLink="false">http://blog.meyer-luenen.de/?p=379</guid>

					<description><![CDATA[Kleine Code Snipplets und Sachen, die ich mir bei Lernen von C# merken möchte.]]></description>
										<content:encoded><![CDATA[
<p class="has-extra-small-font-size">Variablen direkt in Strings ausgeben, ohne &#8222;concat&#8220;</p>



<pre class="wp-block-code"><code>Console.WriteLine($"Hello {name}");</code></pre>



<hr class="wp-block-separator"/>



<p class="has-extra-small-font-size"></p>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">379</post-id>	</item>
	</channel>
</rss>
