MightyOrm / Mighty

A new, small, dynamic micro-ORM. Highly compatible with Massive, but with many essential new features.
BSD 3-Clause "New" or "Revised" License
101 stars 20 forks source link

No table name has been specified #19

Closed comfreakph closed 4 years ago

comfreakph commented 4 years ago

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 });

mikebeaton commented 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:

image

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.)

mikebeaton commented 4 years ago

@comfreakph - did this help? Any further issue? Thanks.

comfreakph commented 4 years ago

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