在.Net教程中(在udemy和一些站点中),我看到它们声明了用于定义模型之间关系的Fluent API。
我试图创建模型,而不是在Fluent API中定义关系,似乎迁移工作和Mysql外键都定义得很好。
我只需要知道,当我们真的需要用Fluent API (OnModelCreating)定义模型之间的关系时
我的模特:
using System.Collections.Generic;
namespace CRSApp.API.Models
{
public class UserGroup
{
public int Id { get; set; }
我有这两个模型(不存在无关属性):
// based on Identity
public class User {
public long? CityId { get; set; }
public virtual City City { get; set; }
}
public class City : Base {
}
public class Base {
public string CreatorId { get; set; }
public virtual User Creator { get; set; }
}
现在,问题是EF核心无法确定User和City之间
假设在使用Ef 6的应用程序中,我有以下模型和流利的配置,这些配置定义了车主与他拥有的汽车/汽车之间的关系。Car与CarOwner的关系为1:0或1,而CarOwner与Car的关系为1:0或多;
public class Car
{
public int Id { get; set; }
public string ChasisNumber { get; set; }
public string EngineNumber { get; set; }
public CarOwner CarOwner { get; set; }
}
public class
在使用带有的值对象内部的实体时,我遇到了列命名问题。EF希望将值对象的实体的外键命名为一个长而丑陋的名称。例如PropertyName_ForeignKeyID。我想要的是用Fluent API控制db列字段的名称。
如果我有一个名为度量值的值对象,并且它具有一个名为UnitOfMeasure的实体的属性,那么这些关系可以正常工作,但是列的命名非常丑陋。
下面是示例模型
public class EntityA
{
public int Id { get; set; }
public Measurement VO { get; set; }
}
public class Me
有没有办法使用Fluent api模型构建器在同一个模型中拥有多个复杂类型的实例?
public class Contact
{
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public Address PersonalAddress { get; set; }
public Address BusinessAddress { get; set; }
}
public class
问题所在
我最近遇到了一个问题,我有一组非常标准的模型类来描述我的业务逻辑,我正在使用fluent Api来描述我的模型类的数据库属性。但是,在我执行Add-Migration InitialMigration之后,包管理器控制台失败,并显示以下输出:
PM> Add-Migration InitialMigration
Scaffolding migration 'InitialMigration'.
System.FormatException: Input string was not in a correct format.
at System.Number
我有一个具有char属性的对象:
public class Product
{
public char Code
{
get;
set;
}
}
实体框架似乎不能映射字符(当我从模型对象创建数据库模式时,数据库中缺少此字段)。有没有什么办法可以使用fluent API来映射字符(例如,映射到字符串)?我不想更改模型对象,因为它们是遗留共享库的一部分。
在过去的三个小时里,我一直在努力想办法解决这个问题,最后我放弃了(我会努力解决这个问题)。但是..。为了确定..。有没有办法在EF6 Fluent API中设置单向0:1/1:1?
考虑:
CREATE TABLE LegacyUsers (
ID INT NOT NULL PRIMARY KEY,
UserName NVARCHAR(50),
EmployeeID INT NULL
)
CREATE TABLE Employees (
ID INT NOT NULL PRIMARY KEY,
EmployeeName NVARCHAR(50)
)
领
我试图使用Fluent API在实体框架核心中创建多到多个关系,这是我的第一个模型:
MyCalculationSelector.cs
public int SortOrder { get; set; }
public string UserString { get { return Name; } }
private IList<CalculationType> _calculationTypes;
public virtual IList<CalculationType> CalculationTypes
{
get { re
EF 4.1在MVC3和延迟加载中,使用代码优先模型
设计正确的模型有困难。请看一看,让我知道我做错了什么。我怎么才能修好它。
我正在使用成员API创建一个帐户。成功创建帐户后。我重定向自动创建联系人记录。contactId (自动数据库生成),userid (存储成员资格api生成的用户id )
这些模型是:
public class Contact
{
public int ContactID { set; get; }
public string UserId { set; get; }
public string LastName { set; get; }
p
我有层次模型(二叉树)。
class Partner
{
public int ID {get; set; }
public string Name { get; set; }
// Parent in the tree.
public virtual Partner BinarParent {get; set;}
// Who is invited partner in tree.
public virtual Partner Sponsor {get; set;}
// Childs partner
我是Entity Framework和C#/.Net的新手,正在尝试创建一个TPH继承模型,我不确定是否应该这样做,所以如果不是,请给我建议,
这是一个模型:
public abstract class Vote
{
public int VoteID { get; set; }
public int UserID { get; set; }
public bool Value { get; set; }
public DateTime DateCreated { get; set; }
public User User { get; set; }
我有一个域模型,其中的属性都有自己的域类型(都有"Value“属性来返回它们的标量值)。例如。
Class FurryFrogMessage {
public Name FurryFrogName {get; private set}
public MaxWeight FurryFrogTopsOutAt {get; private set}
...
}
Class Name {
public string Value;
...
}
...
现在我开始持久化领域模型中的对象,我不确定哪种方法是最好的方法。
我正在使用Entity Framewo
我有一个ASP.NET MVC项目。我有一个这样的模型:
[Validator(typeof(PersonValidation))]
public class Person
{
public int Id { get; set; }
public string Name { get; set; }
public string Family { get; set; }
}
我对上述模型有很强的看法。
我通过fluent验证为我的模型创建了一个验证器。这是我的代码:
public PersonValidation()
{
RuleSet("Up
我遵循了Code First TPT继承的教程:
用户模型包含到BillingDetail的单向导航。CodeFirst将该列命名为"BillingDetail_BillingDetailId“我想使用Fluent API将该列重命名为"BillingDetailId”。这是怎么做的?这是用户模型。
public class User
{
public int UserId { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
我有一个产品模型,它有一个名为ProductTypeId的外键属性。但是,我没有ProductType模型。相反,我有一个TypeListItem模型。我想告诉EF仍然创建一个从ProductTypeId到TypeListItem表中的Id的关系。
我想使用实体框架核心的fluent API来指定这一点,但不知道如何实现。我相信我曾经使用过HasRequired,但我认为EF中没有这种功能。
这里是有争议的模型:
public class Product
{
public int Id { get; set; }
public string Name { get; set; }
我对实体框架(代码优先)相当陌生。这是我的两个实体-
public class Employee
{
public Employee() { }
public long Id {get; set;}
public string Fullname {get; set;}
public virtual ICollection<Attendance> Attendances { get; set; }
}
public class Attendance
{
public Attendance() { }
public DateTim
我一整天都在看的奇怪问题。我正在与实体框架6合作。我面临的问题是我有三个实体:
public partial class Order : ILocationBearingObject
{
public int Id { get; set; }
// other properties and relationships here
public int? OrderProfileId { get; set; }
public int OrderTemplateId { get; set; }
public virtual OrderProfile Prof
所以我有一个现有的类,如下所示:
Public Class Song
<Key>
Public Property GUID As Guid
<ForeignKey("Creator")>
Public Property GUID_Creator As Guid
Public Property Creator As User
End Class
这是完美的工作,我可以添加新的歌曲和所有这些。
最近,我决定我需要用Fluent API来映射一些东西,但是我不想用API重新构建我的整个模型,我所需要的只是禁用级联
为什么要学习Fluent接口,我遇到了这个职位,它指出,使用set提示,一个是突变对象,而with是重新生成一个新对象。
在使用PySpark ()时,我亲眼目睹了这种模式:
# Using "set" to modify exiting object
from pyspark.conf import SparkConf
from pyspark.context import SparkContext
conf = SparkConf()
conf.setMaster("local")
conf.setAppName("My app")
s
我上下查找,尝试了各种不同的方法,可以将AspNetUser表的外键存储在单独的Customer表中。我还是ASP.NET和实体框架的新手,但我读过不少帖子和文档。
目前这是我的
模型
public class Customer
{
[Display (Name="Customer ID")]
public int CustomerID { get; set; }
public string UserId { get; set; }
[ForeignKey("UserId")]
public virtual Applic
您好,我有一个领域模型,这是很好和干净。例如:
public class Blog
{
public int Id {get;set;}
public string Title {get;set;}
public string Body {gets;set;}
}
为什么实体框架强迫我用RowVersion属性污染域模型以提供并发性?
我的模型不想或不需要知道这一点,所以为什么我要强制使用它呢?有没有其他方法来执行并发检查?如果是这样,它是比添加行版本更好/更差,还是更快/更慢?或者,我是否可以将RowVersion添加到不在域模型中的其他位置。我使用的是EF 4.1和
我正在使用rails使用 gem构建json。图书馆真的很棒,它做了很多工作。
但是,我们的DB中的某些列名并不是真正意义上的API显示。
因此,我的问题是:是否可以在资源中重命名属性/属性?
示例:
假设我有带有属性login的模型用户。
class User < ActiveRecord::Base
attr_accessor :login
end
我希望API中的login以username形式出现,例如:
class UserResource < JSONAPI::Resource
attribute :username, map_to: :login
end
谢谢