ASP .NET MVC + LINQ Generated Classes + DataAnnotations
I have a problem, and i hope, u can help me with it. Ok, i'll try to describe my situation:
I've created database. Added table "Orders". Then generated LINQ Classes in dbml file.
Now, i have create action in controller, and i'm trying to set [DisplayName("Other name")] for one or my Order class property (Client name). So, look at this:
/ Core / Extansions.cs
namespace SUPNew.Core
{
public static class Extansions
{
}
[MetadataType(typeof(OrderMetaData))]
public partial class Order
{
}
public class OrderMetaData
{
[DisplayName("ФИО клиента")]
public string ClientFIO { get; set; }
}
}
/ Views / Manager / AddOrder.aspx
<legend>Fields</legend>
<div class="editor-label">
<%: Html.LabelFor(model => model.ClientFIO) %>
</div>
<div class="editor-field">
<%: Html.TextBoxFor(model开发者_开发技巧 => model.ClientFIO) %>
<%: Html.ValidationMessageFor(model => model.ClientFIO) %>
</div>
/ Controllers / ManagerController.cs
using SUPNew.Core;
/ Models / SUPNew.dbml
public partial class Order : INotifyPropertyChanging, INotifyPropertyChanged
{
...
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_ClientFIO", DbType="NVarChar(50) NOT NULL", CanBeNull=false)]
public string ClientFIO
{
get
{
return this._ClientFIO;
}
set
{
if ((this._ClientFIO != value))
{
this.OnClientFIOChanging(value);
this.SendPropertyChanging();
this._ClientFIO = value;
this.SendPropertyChanged("ClientFIO");
this.OnClientFIOChanged();
}
}
}
So, maybe i forgot to make something? I need to display DisplayName for ClientFIO in LabelFor(model => model.ClientFIO) that i've choosen in partial class.
Thx for help.
If i change .dbml file- adding [DisplayName("OtherName")] like this:
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_ClientFIO", DbType="NVarChar(50) NOT NULL", CanBeNull=false)]
[DisplayName("Other name")]
public string ClientFIO
{
get
{
return this._ClientFIO;
}
set
{
if ((this._ClientFIO != value))
{
this.OnClientFIOChanging(value);
this.SendPropertyChanging();
this._ClientFIO = value;
this.SendPropertyChanged("ClientFIO");
this.OnClientFIOChanged();
}
}
}
it works, but when i try to make partial class- isn't. Can somebody help me with partial class for LINQ generated class?
Ok, before when it was like this, it wasn't work:
/Core/Extansions.cs (Namespace SUPNew.Core) (public partial class Order)
/Models/SUPNew.dbml (Namespace SUPNew.Models) (public partial class Order)(generated)
Then, when i replace like this:
/Models/Extansions.cs (Namespace SUPNew.Models) (public partial class Order) /Models/SUPNew.dbml (Namespace SUPNew.Models) (public partial class Order)(generated)
it started to work. But, where is the problem? I used all using in everywhere and Import in View.aspx.
I need to make it work like in first example:
/Core/Extansions.cs (Namespace SUPNew.Core) (public partial class Order)
/Models/SUPNew.dbml (Namespace SUPNew.Models) (public partial class Order)(generated)
精彩评论