Click here to Skip to main content
14,836,552 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Web;
using TM_3_1_16.Models;



namespace TM_3_1_16
{

    public class getfieldsdisplayname : DisplayNameAttribute
    {

        public getfieldsdisplayname(string tblname, string colname)
            : base(GetMessageFromResource(tblname, colname))
        {
        }

 

        private static string GetMessageFromResource(string tblname, string colname)
        {
            DBContext db = new DBContext();

            // colname = base.displayname // I want to retrun which is current porpery name, so that I can find display name in database based on the current field name retrun display name from Database 

            return db.fieldsnames.Where(col => col.ColumnsName == colname).Select(dis => dis.DisplayName).FirstOrDefault().ToString();
        }

    }
  
}
Posted
Updated 6-Jan-16 4:27am
v2
Comments
Maciej Los 6-Jan-16 13:02pm
   
Can you elaborate?
Member 10722203 6-Jan-16 23:42pm
   
Hi,

I would like to create custom data annotation which return display name form the database and i want to pass class name (which treats as table name) and Column name (which treats as column name) and I want to get class name and column name from where i used my custom data annotation

And i need to pass both class name and field name in my EF query then return display name from data base
Maciej Los 7-Jan-16 2:28am
   
OK, but you did not specify what's wrong with your code.
Have a look here: asp.net mvc - Get [DisplayName] attribute of a property in strongly-typed way - Stack Overflow[^]

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900