Notice: file_put_contents(): Write of 5562 bytes failed with errno=28 No space left on device in /var/www/tgoop/post.php on line 50

Warning: file_put_contents(): Only 12288 of 17850 bytes written, possibly out of free disk space in /var/www/tgoop/post.php on line 50
Web Devs@fullStackDevs P.480
FULLSTACKDEVS Telegram 480
#ادامه
#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/480
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/480

View MORE
Open in Telegram


Telegram News

Date: |

Although some crypto traders have moved toward screaming as a coping mechanism, several mental health experts call this therapy a pseudoscience. The crypto community finds its way to engage in one or the other way and share its feelings with other fellow members. Today, we will address Telegram channels and how to use them for maximum benefit. Some Telegram Channels content management tips To upload a logo, click the Menu icon and select “Manage Channel.” In a new window, hit the Camera icon. Write your hashtags in the language of your target audience.
from us


Telegram Web Devs
FROM American