c# - Retrieve Name value from ColumnAttribute for Entity Framework batch deletes -


I want to execute batch delete in the unit framework (for display reasons):

  Context.ExecuteStoreCommand ("Remove from {0} {1} = {2}", tagname, columnname, column well);  

I want to know how to get the name of the column from the property.

  [Column ("column name")] Public Property Asset Name {get; Set; }  

I also use EF5 with the Oracle Provider.

You use.

  public class's mycollege {[column ("column name")] get public property property name; Set; Pattern:    Public Static String GetColumnName & lt; T & gt; (String propertyName) {string result = null}}  

if (string.IsNullOhWhiteSpace (propertyName)) {throw new argument (NullException); } Var table type = typef (t); Var Properties = tableType.GetProperties (BindingFlags.GetProperty | BindingFlags.Instance | BindingFlags.Public); Var property = properties. Where (P = & gt; p.Name.Equals (propertyName, StringComparison.CurrentCultureIgnoreCase)) .FirstOrDefault (); If (property == faucet) {new exception throw ("property name not found."); // bad example} and {result = property.Name; // If no column attribute is present; Var attribute = property. GetCustomAttributes (); Var attribute = attributes. Where (a => is a column entry). FirstOrDefault () as ColumnAttribute; If (attribute! = Null) {result = attribute.Name; }} Return result; }

For example:

  Public square MyClass {[column ("column name")] {get public property property name; Set; }} Var Results = GetColumnName & lt; MyClass & gt; ("Property name"); Console.WriteLine (results);  

Result:

Column


Comments

Popular posts from this blog

winforms - C# Form - Property Change -

javascript - amcharts makechart not working -

java - Algorithm negotiation fail SSH in Jenkins -