1

Topic: Designation of fields EF

Kind time of days! In the project (MVC 5) the model is created from basis MS SQL (Data First). When I create the controler on the basis of model (with standard  etc.) in  everywhere as titles that is interposed that like

@Html. LabelFor (model => model. NMK_CODE, htmlAttributes: new {@class = "control-label col-md-2"})

What best practice not to replace it each time on  a line "the Nomenclature code" in everyone standard ?

2

Re: Designation of fields EF

denis_viktorovich wrote:

not to replace it each time on  a line

replace for us then once and show)

3

Re: Designation of fields EF

Petro123, as always....
denis_viktorovich, , is any attribute (Description or that type) which you can hang on property NMK_CODE, and LabelFor will substitute it as the label text

4

Re: Designation of fields EF

... Or DisplayName....

5

Re: Designation of fields EF

Shocker. Pro wrote:

Petro123, as always....
denis_viktorovich, , is any attribute (Description or that type) which you can hang on property NMK_CODE, and LabelFor will substitute it as the label text

Here I about same thought and at creation of tables everywhere set property MS_Description with the necessary text, however Html. LabelFor pulls Name.

6

Re: Designation of fields EF

Shocker. Pro wrote:

Petro123, as always....

you too as always are dissatisfied).
You old, skilled. And I did not understand where it was going to substitute. From model it always so will be.

7

Re: Designation of fields EF

In a class of your model attributes make, an example:

[Display (Name = "the credit Total", ShortName = "the credit Total")]
public decimal? Amount {get; set;}

8

Re: Designation of fields EF

[spoiler]

Petro123 wrote:

You old, skilled.

[img=http://www.stihi.ru/pics/2016/09/07/7287.jpg] [/spoiler]

9

Re: Designation of fields EF

Konst_One wrote:

in a class of your model attributes make, an example:

[Display (Name = "the credit Total", ShortName = "the credit Total")]
public decimal? Amount {get; set;}

Another matter.
Simply and beautifully).

10

Re: Designation of fields EF

Konst_One wrote:

in a class of your model attributes make, an example:

[Display (Name = "the credit Total", ShortName = "the credit Total")]
public decimal? Amount {get; set;}

"Manual changes to this file will be overwritten if the code is regenerated.", I so understand it is necessary to create one more class for display. I meant, whether there is no possibility to pull out for example immediately Description from field property of the table.

11

Re: Designation of fields EF

denis_viktorovich wrote:

... I so understand it is necessary to create one more class for display.

It is not necessary. Directly in model describe. Add

using System. ComponentModel. DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
denis_viktorovich wrote:

I meant, whether there is no possibility to pull out for example immediately Description from field property of the table.

Did not hear about such)

12

Re: Designation of fields EF

denis_viktorovich;
The best practice
1. To have a layer where there are the objects representing the tables of a DB
2. To have a layer of domain objects which are formed on the basis of objects 1. Objects 1 are no means always equal to objects 2
3. To have viewmodel for your representation which to be under construction on a basis 2
Requirements on 3 can be weakened, if objects 2 strongly enough coincides with objects for View.
At you objects 1 are used for 3 - here and ask, as a hedgehog with  to combine.
The answer idle time - it is necessary to avoid a situation when so it is necessary to do.
Object EF - at it the task - presents the DB table
The object of model View has other task. They with each other are badly combined.
As acknowledgement of it serves  a question