Closed comfreakph closed 4 years ago
The short answer, you want to do:
dynamic membership = db.SingleFromQuery("SELECT * FROM aspnet_Membership WHERE Email=@0", user.Email);
dynamic userRoles = db.SingleFromQuery("SELECT * FROM aspnet_UsersInRoles WHERE UserId = @0", membership.UserId);
dynamic role = db.SingleFromQuery("SELECT * FROM aspnet_Roles WHERE RoleId = @0", userRoles.RoleId);
Note the IntelliSense on the method you were using:
The constructor for non-table-specific instances is a constructor for the same class type as for table-specific instances, you just don't pass in a tableName
parameter. It has the same methods, but the table-specific methods will produce an error.
By the way, you can shorten the way you are passing params
arguments, as I've done in my replacement code above. This is a feature of C#, not just of Mighty/Massive. See also this example, using the variant of Single
you were originally calling, and passing two params
arguments:
var db = new MightyOrm<Membership>(connectionString);
dynamic membership = db.Single("WHERE Email=@0 AND IsLockedOut=@1", user.Email, isLockedOut);
(Also, the initial "WHERE ..." in this where
string is optional.)
@comfreakph - did this help? Any further issue? Thanks.
yes, thank you so much
On Thu, Mar 19, 2020 at 8:06 PM Mike Beaton notifications@github.com wrote:
Closed #19 https://github.com/MightyOrm/Mighty/issues/19.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/MightyOrm/Mighty/issues/19#event-3145259458, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAFKG4BHW4H5XCXJ3WEDGNTRIIDDRANCNFSM4LF7N2MA .
--
John Alfred Dafielmoto about.me/johnad [image: John Alfred Dafielmoto on about.me] http://about.me/johnad
i tried to use the non-table specific instance but error popup "No table name has been specified" this is the code I created:
var db = new MightyOrm(connectionString); dynamic membership = db.Single("SELECT * FROM aspnet_Membership WHERE Email=@0",new object[] { user.Email }); dynamic userRoles = db.Single("SELECT * FROM aspnet_UsersInRoles WHERE UserId = @0", new object[] { membership.UserId }); dynamic role = db.Single("SELECT * FROM aspnet_Roles WHERE RoleId = @0", new object[] { userRoles.RoleId });