Is it possible to create a Insert method (ADO.NET) based on a class?

Hi,

Would it be possible for me to create an insert DAL from an existing class?

So something like:

sqlCmd.Parameters.Add("@moduleID", SqlDbType.Int, 4).Value = attachment.ModuleID;
sqlCmd.Parameters.Add("@branchID", SqlDbType.Int, 4).Value = attachment.BranchID;
sqlCmd.Parameters.Add("@nodeID", SqlDbType.Int, 4).Value = attachment.NodeID;
sqlCmd.Parameters.Add("@attachmentGuid", SqlDbType.Char, 36).Value = attachment.AttachmentGuid;
sqlCmd.Parameters.Add("@attachmentType", SqlDbType.Int, 4).Value = (int)attachment.AttachmentType;
sqlCmd.Parameters.Add("@userID", SqlDbType.Int, 4).Value = attachment.UserID;
sqlCmd.Parameters.Add("@userName", SqlDbType.NVarChar, 256).Value = attachment.UserName;
sqlCmd.Parameters.Add("@fileName", SqlDbType.NVarChar, 255).Value = attachment.FileName;
sqlCmd.Parameters.Add("@friendlyFileName", SqlDbType.NVarChar, 255).Value = attachment.FriendlyFileName;
sqlCmd.Parameters.Add("@fileSize", SqlDbType.Int, 4).Value = attachment.FileSize;
sqlCmd.Parameters.Add("@isApproved", SqlDbType.Bit, 1).Value = attachment.IsApproved;
sqlCmd.Parameters.Add("@caption", SqlDbType.NVarChar, 255).Value = attachment.Caption;

All the fields are mapped directly from my Attachment class.

2 comments
Comment actions Permalink

I believe using ORM is a better solution to avoid this. google nhibernate...

0
Comment actions Permalink

Hello RSCoder,

No, there is no such feature in ReSharper. You could write a plugin :)

Sincerely,
Ilya Ryzhenkov

JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"


IR> Hi,
IR>
IR> Would it be possible for me to create an insert DAL from an existing
IR> class?
IR>
IR> So something like:
IR>
IR> sqlCmd.Parameters.Add("@moduleID", SqlDbType.Int, 4).Value =
IR> attachment.ModuleID;
IR> sqlCmd.Parameters.Add("@branchID", SqlDbType.Int,
IR> 4).Value = attachment.BranchID;
IR> sqlCmd.Parameters.Add("@nodeID", SqlDbType.Int,
IR> 4).Value = attachment.NodeID;
IR> sqlCmd.Parameters.Add("@attachmentGuid",
IR> SqlDbType.Char, 36).Value = attachment.AttachmentGuid;
IR> sqlCmd.Parameters.Add("@attachmentType",
IR> SqlDbType.Int, 4).Value = (int)attachment.AttachmentType;
IR> sqlCmd.Parameters.Add("@userID", SqlDbType.Int,
IR> 4).Value = attachment.UserID;
IR> sqlCmd.Parameters.Add("@userName",
IR> SqlDbType.NVarChar, 256).Value = attachment.UserName;
IR> sqlCmd.Parameters.Add("@fileName",
IR> SqlDbType.NVarChar, 255).Value = attachment.FileName;
IR> sqlCmd.Parameters.Add("@friendlyFileName",
IR> SqlDbType.NVarChar, 255).Value = attachment.FriendlyFileName;
IR> sqlCmd.Parameters.Add("@fileSize", SqlDbType.Int,
IR> 4).Value = attachment.FileSize;
IR> sqlCmd.Parameters.Add("@isApproved", SqlDbType.Bit,
IR> 1).Value = attachment.IsApproved;
IR> sqlCmd.Parameters.Add("@caption",
IR> SqlDbType.NVarChar, 255).Value = attachment.Caption;
IR> All the fields are mapped directly from my Attachment class.
IR>


0

Please sign in to leave a comment.