﻿<?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 Sharp Sınıfları Oluşturmak &#8211; SQL Server Eğitimleri</title>
	<atom:link href="https://sqlserveregitimleri.com/etiket/c-sharp-siniflari-olusturmak/feed" rel="self" type="application/rss+xml" />
	<link>https://sqlserveregitimleri.com</link>
	<description>SQL Server ile ilgili her şey</description>
	<lastBuildDate>Tue, 05 Oct 2021 19:48:49 +0000</lastBuildDate>
	<language>tr</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.7.1</generator>
	<item>
		<title>SQL Server&#8217;da Tablolardan C Sharp Sınıfları Oluşturmak</title>
		<link>https://sqlserveregitimleri.com/sql-serverda-tablolardan-c-sharp-siniflari-olusturmak</link>
		
		<dc:creator><![CDATA[Yavuz Selim Kart]]></dc:creator>
		<pubDate>Tue, 05 Oct 2021 19:48:49 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[C Sharp Sınıfları Oluşturmak]]></category>
		<category><![CDATA[sql ile csharp sınıfı oluşturmak]]></category>
		<category><![CDATA[Tablolardan C Sharp Sınıfları Oluşturmak]]></category>
		<guid isPermaLink="false">https://sqlserveregitimleri.com/?p=11062</guid>

					<description><![CDATA[Herkese merhaba, Bu yazıda SQL Server&#8217;da Tablolardan C Sharp sınıfları oluşturmak ile ilgili bilgi paylaşacağım. Programlama dünyasında bu tarz şeyleri kullanmak sizlere hız kazandırabilir. Bazıları...]]></description>
										<content:encoded><![CDATA[<p>Herkese merhaba,</p>
<p>Bu yazıda SQL Server&#8217;da Tablolardan <strong>C Sharp</strong> sınıfları oluşturmak ile ilgili bilgi paylaşacağım.</p>
<p>Programlama dünyasında bu tarz şeyleri kullanmak sizlere hız kazandırabilir.</p>
<p>Bazıları ne gereği var, ben hızlı hızlı bu kodları oluşturabilirim diyebilir. Herkesin yoğurt yeme biçimi farklı.</p>
<p>Aşağıdaki kodu kullanarak siz de dilediğiniz tablonun <strong>C Sharp</strong> sınıfını kolayca oluşturabilirsiniz.</p>
<pre class="line-numbers"><code class="language-sql">DECLARE @TableName sysname = 'Products';
DECLARE @Result VARCHAR(MAX) = 'public class ' + @TableName + '
{';
SELECT @Result = @Result + '
    public '     + (CASE
                        WHEN ColumnName = 'RowVersion' THEN
                            'byte[]'
                        ELSE
                            ColumnType
                    END
                   ) + NullableSign + ' ' + ColumnName + ' { get; set; }
'
FROM
(
    SELECT REPLACE(col.name, ' ', '_') ColumnName,
           column_id ColumnId,
           CASE typ.name
               WHEN 'bigint' THEN
                   'long'
               WHEN 'binary' THEN
                   'byte[]'
               WHEN 'bit' THEN
                   'bool'
               WHEN 'char' THEN
                   'string'
               WHEN 'date' THEN
                   'DateTime'
               WHEN 'datetime' THEN
                   'DateTime'
               WHEN 'datetime2' THEN
                   'DateTime'
               WHEN 'datetimeoffset' THEN
                   'DateTimeOffset'
               WHEN 'decimal' THEN
                   'decimal'
               WHEN 'float' THEN
                   'float'
               WHEN 'image' THEN
                   'byte[]'
               WHEN 'int' THEN
                   'int'
               WHEN 'money' THEN
                   'decimal'
               WHEN 'nchar' THEN
                   'string'
               WHEN 'ntext' THEN
                   'string'
               WHEN 'numeric' THEN
                   'decimal'
               WHEN 'nvarchar' THEN
                   'string'
               WHEN 'real' THEN
                   'double'
               WHEN 'smalldatetime' THEN
                   'DateTime'
               WHEN 'smallint' THEN
                   'short'
               WHEN 'smallmoney' THEN
                   'decimal'
               WHEN 'text' THEN
                   'string'
               WHEN 'time' THEN
                   'TimeSpan'
               WHEN 'timestamp' THEN
                   'timestamp'
               WHEN 'rowversion' THEN
                   'byte[]'
               WHEN 'tinyint' THEN
                   'byte'
               WHEN 'uniqueidentifier' THEN
                   'Guid'
               WHEN 'varbinary' THEN
                   'byte[]'
               WHEN 'varchar' THEN
                   'string'
               ELSE
                   'UNKNOWN_' + typ.name
           END ColumnType,
           CASE
               WHEN col.is_nullable = 1
                    AND typ.name IN ( 'bigint', 'bit', 'date', 'datetime', 'datetime2', 'datetimeoffset', 'decimal',
                                      'float', 'int', 'money', 'numeric', 'real', 'smalldatetime', 'smallint',
                                      'smallmoney', 'time', 'tinyint', 'uniqueidentifier'
                                    ) THEN
                   '?'
               ELSE
                   ''
           END NullableSign
    FROM sys.columns col
        JOIN sys.types typ
            ON col.system_type_id = typ.system_type_id
               AND col.user_type_id = typ.user_type_id
    WHERE object_id = OBJECT_ID(@TableName)
) t
ORDER BY ColumnId;
SET @Result = @Result + '
}';
PRINT @Result;</code></pre>
<p>Ben örneğimi <strong>Northwind</strong> veri tabanı üzerinde <strong>Categories</strong> tablosunu kullanarak yaptım siz kendi veri tabanınızda deneyebilirsiniz.</p>
<p>Yukarıdaki kod bloğunu çalıştırdığınızda aşağıdaki sonucu göreceksiniz.</p>
<p><img fetchpriority="high" decoding="async" class="alignnone wp-image-11065 size-full" src="https://sqlserveregitimleri.com/wp-content/uploads/2021/10/sql-serverda-tablolardan-c-sharp-siniflari-olusturmak-1.jpg" alt="" width="700" height="474" srcset="https://sqlserveregitimleri.com/wp-content/uploads/2021/10/sql-serverda-tablolardan-c-sharp-siniflari-olusturmak-1.jpg 700w, https://sqlserveregitimleri.com/wp-content/uploads/2021/10/sql-serverda-tablolardan-c-sharp-siniflari-olusturmak-1-315x213.jpg 315w, https://sqlserveregitimleri.com/wp-content/uploads/2021/10/sql-serverda-tablolardan-c-sharp-siniflari-olusturmak-1-443x300.jpg 443w, https://sqlserveregitimleri.com/wp-content/uploads/2021/10/sql-serverda-tablolardan-c-sharp-siniflari-olusturmak-1-199x135.jpg 199w" sizes="(max-width: 700px) 100vw, 700px" /></p>
<p>Görüldüğü üzere <strong>Categories</strong> tablosunu sınıf olarak oluşturdu. Aşağıda bunu görebilirsiniz.</p>
<pre class="line-numbers"><code class="language-csharp">public class Products
{
    public int ProductID { get; set; }

    public string ProductName { get; set; }

    public int? SupplierID { get; set; }

    public int? CategoryID { get; set; }

    public string QuantityPerUnit { get; set; }

    public decimal? UnitPrice { get; set; }

    public short? UnitsInStock { get; set; }

    public short? UnitsOnOrder { get; set; }

    public short? ReorderLevel { get; set; }

    public bool Discontinued { get; set; }

}</code></pre>
<p>Herkese çalışma hayatında ve yaşamında başarılar kolaylıklar.</p>
<div class='epvc-post-count'><span class='epvc-eye'></span>  <span class="epvc-count"> 524</span><span class='epvc-label'> Kez Okundu</span></div>]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
