加入两个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) 所有基本的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
我正在尝试将设备的 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) 我正在开发一个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) 我在两个类之间映射数据,其中一个类是在另一个类(销售订单)中创建或修改数据的采购订单.如果销售订单值不为空,我还会保留更改内容的事务日志.你能告诉一种方法来制作这种通用的吗?
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) asp.net-mvc ×2
c# ×2
anonymous ×1
arduino ×1
ethernet ×1
generics ×1
join ×1
json ×1
json.net ×1
lambda ×1
linq ×1
overloading ×1
sql-server ×1