Reputation: 345
How can I retrieve ROWID value from EF DBSet object: I would like to do something like below:
var accounts = _context.Accounts.Include(x => x.UserFunctions);
foreach (var account in accounts)
{
int rowid = account.GetRowId();
}
where Accounts
is defined in the context like this:
public class DataContext : IdentityDbContext<Account>
{
public DbSet<Account> Accounts { get; set; }
}
and Account
is defined like:
public class Account : IdentityUser
{
public string Title { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
}
Is there a way of doing account.GetRowId()?
Upvotes: 0
Views: 159
Reputation: 304
You should be getting the unique Id for the inserted row By(as per your example)
Int rowId=account.Id;
To achieve more control over your code, you can do,
public class Account : IdentityUser
{
[Key] //you can also add options i.e: DatabaseGenerated(DatabaseGeneratedOption.Identity)
Public int RowId{get;set;} //also you can fully manually handle it here however you want
public string Title { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
}
Upvotes: 0