Дано:
public class User
{
public int Id { get; private set; }
public string Name { get; set; }
public int Age { get; set; }
}
public class Publication
{
private int authorId;
public Publication(int id, string content, int authorId)
{
Id = id;
Content = content;
this.authorId = authorId;
}
public Publication(User author)
{
authorId = author.Id;
}
public int Id { get; private set; }
public string Content { get; set; }
public User Author
{
get
{
using DataBase db = new DataBase();
return db.Users.Single(u => u.Id == authorId);
}
}
}
Таблицы в бд:
Users:
Id | int
Name | varchar(32)
Age | int
Publications:
Id | int
Content | nvarchar(500)
AuthorId | int
Вопрос:
Как мне при чтении из БД вызывать конструктор public Publication(int id, string content, int authorId), а при записи в БД записывать свойство Author.Id ?
Основные этапы разработки сайта для стоматологической клиники
Продвижение своими сайтами как стратегия роста и независимости