Custom Expression in Linq-to-Sql Designer

According to Microsoft:

http://msdn.microsoft.com/de-de/library/system.data.linq.mapping.columnattribute.expression.aspx

You can add an expression to the Linq-to-SQL mapping.

But how to configure or add them to Visual Studio in Designer? The problem is, when I manually add it to xxY.designer.cs, it will be lost when changed.

//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//     Runtime Version:2.0.50727.4927
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

This is generated by:

   [Column(Name="id", Storage="_id", DbType="Int")]
   public System.Nullable<int> id
   {
    ...

But I need something like this

[Column(Name="id", Storage="_id", DbType="Int", Expression="Max(id)")]
public System.Nullable<int> id
{
  ...

Thank.

+3
source share
3 answers

: mmmm , , , , : D

, , , LinQ-to-SQL, , .

, , L2S. ( , DataContext), , :

public partial class File
{
}

, .. 'other' File.

0

klugy, linq2sql 'id' 'xid' ( - ) .

, Wim Haanstra, 'id', , get set , "xid".

:

public partial class File
{
  public int? id
  {
     get { return xid; }
     set { xid = value; }
  }
}

this is most often done to map fields in the database to another type in the object, for example. int in the database for listing in the object, byte / small font / etc. in the database, logical in the object. or add attributes such as [DataMember] to the property.

0
source

Source: https://habr.com/ru/post/1743808/


All Articles