开发者

Entity Framework WPF/MVVM

Am returning records in EF 4 in a WPF app using MVVM

Is there a way to give me a record ordinal for records returned.... ie 4 records would have 1 2 3 4 or 0 start...like in recordsets or datasets

Is there such a thing in EF?

Or if n开发者_Go百科ot has anyone got a way of doing this in my viewmodels as a property ie RowNo

cheers George


Just use a Linq statement and do it in C#:

using (var database = new DataContext())
{
  int count = 0;
  this.YourDataBoundProperty = (
    from row in database.YourTable
    select new 
    {
      Id = count++,
      Column1 = row .Column1,
      Column2 = row .Column2,
      //.. etc.
    }
 ).ToArray();  //If you want an array
}

You can also use let to do this, but I prefer using a regular C# variable.


Yes, one way of doing this is by creating and working with POCO classes (there is an extension for VS which makes it easy to do this)...

Obviously, your tables would contain an Id column of type int that is set to auto-increment...

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜