Notice: file_put_contents(): Write of 18060 bytes failed with errno=28 No space left on device in /var/www/tgoop/post.php on line 50
Web Devs@fullStackDevs P.546
FULLSTACKDEVS Telegram 546
Forwarded from Web Devs
#ادامه
#Keyless_Entity


🔹مثال
ابتدا مدل های زیر را تعریف میکنیم
public class Blog
{
public int BlogId { get; set; }
public string Name { get; set; }
public string Url { get; set; }
public ICollection<Post> Posts { get; set; }
}

public class Post
{
public int PostId { get; set; }
public string Title { get; set; }
public string Content { get; set; }
public int BlogId { get; set; }
}
▪️در
خط زیر نیست یک view ساده در دیتابیس تعریف میکتیم که هر Post به همراه Blog مرتبطش برمیگرداند.

db.Database.ExecuteSqlRaw(
@
"CREATE VIEW View_BlogPostCounts AS
SELECT b.Name, Count(p.PostId) as PostCount
FROM Blogs b
JOIN Posts p on p.BlogId = b.BlogId
GROUP BY b.Name"
);
▪️در
نهایت Keyless Entity خود را متناظر با نوع خروچی View ای که ساختیم به اینصورت تعریف میکنیم.

public class BlogPostsCount
{
public string BlogName { get; set; }
public int PostCount { get; set; }
}
▪️و
آنرا بدین شکل در متد OnModelCreating کانفیگ میکنیم.
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder
.Entity<BlogPostsCount>(eb =>
{
eb.HasNoKey();
eb.ToView("View_BlogPostCounts");
eb.Property(v => v.BlogName).HasColumnName("Name");
});
}
▪️ حال
نوبت به معرفی کرد keyless Entity به DbContext میباشد.که بدین شکل در Db Context تعریف میشود
public DbQuery<BlogPostsCount> BlogPostCounts { get; set; }

در آخر نیز بدین شکل میتوانید از آن استفاده کنید.
var postCounts = db.BlogPostCounts.ToList();

foreach (var postCount in postCounts)
{
Console.WriteLine($"{postCount.BlogName} has {postCount.PostCount} posts.");
Console.WriteLine();
}

لینک منبع
🔹سورس این پست رو در اینجا بررسی کنید.

@FullStackDevs



tgoop.com/fullStackDevs/546
Create:
Last Update:

#ادامه
#Keyless_Entity


🔹مثال
ابتدا مدل های زیر را تعریف میکنیم
public class Blog
{
public int BlogId { get; set; }
public string Name { get; set; }
public string Url { get; set; }
public ICollection<Post> Posts { get; set; }
}

public class Post
{
public int PostId { get; set; }
public string Title { get; set; }
public string Content { get; set; }
public int BlogId { get; set; }
}
▪️در
خط زیر نیست یک view ساده در دیتابیس تعریف میکتیم که هر Post به همراه Blog مرتبطش برمیگرداند.

db.Database.ExecuteSqlRaw(
@
"CREATE VIEW View_BlogPostCounts AS
SELECT b.Name, Count(p.PostId) as PostCount
FROM Blogs b
JOIN Posts p on p.BlogId = b.BlogId
GROUP BY b.Name"
);
▪️در
نهایت Keyless Entity خود را متناظر با نوع خروچی View ای که ساختیم به اینصورت تعریف میکنیم.

public class BlogPostsCount
{
public string BlogName { get; set; }
public int PostCount { get; set; }
}
▪️و
آنرا بدین شکل در متد OnModelCreating کانفیگ میکنیم.
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder
.Entity<BlogPostsCount>(eb =>
{
eb.HasNoKey();
eb.ToView("View_BlogPostCounts");
eb.Property(v => v.BlogName).HasColumnName("Name");
});
}
▪️ حال
نوبت به معرفی کرد keyless Entity به DbContext میباشد.که بدین شکل در Db Context تعریف میشود
public DbQuery<BlogPostsCount> BlogPostCounts { get; set; }

در آخر نیز بدین شکل میتوانید از آن استفاده کنید.
var postCounts = db.BlogPostCounts.ToList();

foreach (var postCount in postCounts)
{
Console.WriteLine($"{postCount.BlogName} has {postCount.PostCount} posts.");
Console.WriteLine();
}

لینک منبع
🔹سورس این پست رو در اینجا بررسی کنید.

@FullStackDevs

BY Web Devs


Share with your friend now:
tgoop.com/fullStackDevs/546

View MORE
Open in Telegram


Telegram News

Date: |

Deputy District Judge Peter Hui sentenced computer technician Ng Man-ho on Thursday, a month after the 27-year-old, who ran a Telegram group called SUCK Channel, was found guilty of seven charges of conspiring to incite others to commit illegal acts during the 2019 extradition bill protests and subsequent months. How to create a business channel on Telegram? (Tutorial) The group’s featured image is of a Pepe frog yelling, often referred to as the “REEEEEEE” meme. Pepe the Frog was created back in 2005 by Matt Furie and has since become an internet symbol for meme culture and “degen” culture. To upload a logo, click the Menu icon and select “Manage Channel.” In a new window, hit the Camera icon. Telegram message that reads: "Bear Market Screaming Therapy Group. You are only allowed to send screaming voice notes. Everything else = BAN. Text pics, videos, stickers, gif = BAN. Anything other than screaming = BAN. You think you are smart = BAN.
from us


Telegram Web Devs
FROM American