开发者

Optimal method to display Entities plus additional information?

Let's say I have an Entity in my Entity Framework Model that is named Server, and has a string property named Address.

When my View is loaded, I need to:

  1. Get a list of Addresses from the Model (simple enough).
  2. Run out and get some data from each of the Addresses via JSON.
  3. Display a DataGrid that has the server address, with all the info it fetched.

NO saving functionality is needed, this is just displaying information. Do I need to make an all-new obje开发者_开发百科ct and populate a list of these to bind to? If so, would it be bad to inherit from my POCO Entities, add more fields, and populate/bind to a list of those? Or would it be better to do a Linq query to my database, generate an anonymously-typed collection on the fly, and bind to that? Or is there another better way I'm not aware of?

As you may tell from my question history, I'm new to .NET4/WPF and learning as I go on this project, but I'm trying to learn how to do it right and not brute-force it, so sorry if it's an obvious question to you pros here. :)


If you know you will need the data for sure every time I would recommend to load it together. Assuming you model looks something like this: Server -> ServerAddresses -> AddressDetail then I think you would be best off populating all the info in one shot.

When loading your data do something like this:

using (var context in new EntityContext())
{
  var model = context.Servers.Include("ServerAddresses.AddressDetail").Where(s => s.Foo == "Bar")
}

and bind your view to that model rather than lazy loading this for each item later. And yes it would be best to load this model into a custom structure for serialization (which I am assuming you are doing since you are referring to JSON.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜