It's possible I shouldn't even be attempting this in the first place, but here's what I have so far:
public List<int> AuthorIDs
{
get
{
var l = new List<int>();
using (var context = new GarbageEntities())
{
foreach (var author in context.Authors.Where(a => a.Books.Any(b => b.BookID == this.BookID)).ToList())
{
l.Add(author.AuthorID);
}
}
return l;
}
set; //compiler error
}
How would I leave the above setter without any sort of custom logic? In the olden days I think you would just use:
set { authorIDs = value; }
which doesn't work now.
Is this whole idea just terrible to begin with?
Edit:
To answer some people's questions: I'm attempting to combine MVC with Data Annotation validation, with default binding, with Entity Framework 4.0...and failing quite fantastically, I believe.
No, it's not possible. Either everything is explicit, or the whole property is automatic. Anyway, in that case the setter doesn't seem to make any sense... there should be no setter at all.
Also, I think you should make it a method. It would make it clearer to the caller that it performs a possibly lenghty calculation. It's also against guidelines to perform complex processing in a property.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With