gpt4 book ai didi

c# - Linq-to-Sql 设计器中的自定义表达式

转载 作者:行者123 更新时间:2023-11-30 18:44:31 24 4
gpt4 key购买 nike

根据微软的说法:

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

可以将表达式添加到 Linq-to-SQL 映射。

但是如何在设计器中的 Visual Studio 中配置或添加它们呢?问题是,当我将它手动添加到 x XYZ.designer.cs 时,它会在更改时丢失。

//------------------------------------------------------------------------------
// <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>
//------------------------------------------------------------------------------

这是生成的:

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

但是我需要这样的东西

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

谢谢。

最佳答案

根据这篇文章:

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

当您使用 CreateDatabase 将列定义为包含计算值时,您应该使用 ColumnAttribute.Expression 属性。所以你应该看看这篇文章:

http://msdn.microsoft.com/en-us/library/Bb399420%28v=VS.100%29.aspx

另一种方法是在您的 sql server 上定义表达式,这样它就会被 LINQ 设计器映射。

关于c# - Linq-to-Sql 设计器中的自定义表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2757772/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com