小编Pet*_*ete的帖子

LINQ Lambda加入错误 - 无法从使用中推断出来

加入两个DbSets时遇到了麻烦,并继续收到"无法推断的错误".我努力寻找解决方案,所以我想我会分享我的简单答案.Jon Skeet和其他人有几篇很棒的帖子,但大多数答案都在我脑海中.

这是导致我麻烦的代码:

using(var db = new SomeDataContext())
    {
    db.DemandData
        .Where(demand=> demand.ID == SearchID)
        .Join(db.CUST_ORDER_LINE,
            supply=> new { supply.LINE, supply.SALES_ORDER_ID },
            demand=> new { demand.LINE_NO, demand.CUST_ORDER_ID },
            (supply, demand) => new { custOrderLineReturn = demand })
        .Select(s => s.custOrderLineReturn )
        .ToList();
    }
Run Code Online (Sandbox Code Playgroud)

linq lambda join

26
推荐指数
1
解决办法
7784
查看次数

实体框架查询结果重复

  • 我创建了一个连接几个表的SQL视图,并且在SQL Manager中进行测试时,它提供了正确的数据(如果它们有所不同,则这些是复杂的连接).
  • 在MVC中,我创建了一个(数据优先)实体数据模型,然后添加了代码生成.
  • 我在控制器中有一个LINQ查询,生成一个idex页面.

所有基本的MVC内容.

当我运行应用程序时,我收到重复的记录.要进一步限定,如果订单有多行,则返回"订单"中每行的第一条记录.

SQL Results
Order, Line, Part
12345, 1, 3829138120
12345, 2, 1238401890

MVC/EF Results
Order, Line
12345, 1, 3829138120
12345, 1, 3829138120
Run Code Online (Sandbox Code Playgroud)

有关这个问题的原因的任何想法?

sql-server asp.net-mvc entity-framework duplicate-data multiple-resultsets

6
推荐指数
1
解决办法
1367
查看次数

Arduino 显示 Ethernet.localIP()

我正在尝试将设备的 IP 地址分配给一个字符串变量。当我 Serial.println(Ethernet.localIP())用来测试时,它以八位字节显示 IP 地址。如果我使用,String(Ethernet.localIP());那么它会将其显示为小数。

有没有办法将八位字节格式分配给变量?

 String MyIpAddress;

 void StartNetwork()
 {
     Print("Initializing Network");
     if (Ethernet.begin(mac) == 0) {
     while (1) {
       Print("Failed to configure Ethernet using DHCP");
       delay(10000);
     }
   }
   Serial.println(Ethernet.localIP());        //displays: 192.168.80.134
   MyIpAddress = String(Ethernet.localIP());
   Serial.println(MyIpAddress);               //displays: 2253433024
 }
Run Code Online (Sandbox Code Playgroud)

ethernet arduino

5
推荐指数
1
解决办法
8665
查看次数

c#JSON序列化使用值而不是属性名称

我正在开发一个JSON驱动的项目,我想为该SessionManager对象提供一个动态的权限列表.虽然我可以使用一组键值对进行权限,但我想知道是否可以删除属性名称,以便Permission值,IsAllowed值.

public class SessionPermission
{
    public string Permission { get; set; }
    public bool IsAllowed { get; set; }
}


public class SessionManager
{
    public string UserName { get; set; }
    public string Password { get; set; }
    public List<SessionPermission> Permissions { get; set; }

    public void SetPermissions()

    {
        Permissions = new List<SessionPermission>
        {
            new SessionPermission {Permission = "CreateUsers", IsAllowed = false},
            new SessionPermission {Permission = "EditUsers", IsAllowed = false}, …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-mvc serialization json json.net

4
推荐指数
1
解决办法
1671
查看次数

通用财产比较 - 确定财产变化

我在两个类之间映射数据,其中一个类是在另一个类(销售订单)中创建或修改数据的采购订单.如果销售订单值不为空,我还会保留更改内容的事务日志.你能告诉一种方法来制作这种通用的吗?

private static DateTime CheckForChange(this DateTime currentValue, 
    DateTime newValue, string propertyName)
{
    if (currentValue == newValue) return currentValue;
    LogTransaction(propertyName);
    return newValue;
}
private static decimal CheckForChange(this decimal currentValue, 
    decimal newValue, string propertyName)
{
    if (currentValue == newValue) return currentValue;
    LogTransaction(propertyName);
    return newValue;
}
private static int CheckForChange(this int currentValue, 
    int newValue, string propertyName)
{
    if (currentValue == newValue) return currentValue;
    LogTransaction(propertyName);
    return newValue;
}
Run Code Online (Sandbox Code Playgroud)

原始建议的代码示例

private static T CheckForChange<T>(this T currentValue, T newValue, 
    string propertyName) where T : ???
{ …
Run Code Online (Sandbox Code Playgroud)

c# generics overloading anonymous

1
推荐指数
1
解决办法
639
查看次数