columnattribute

How do I get the ColumnAttributes from a Linq.Table<TEntity>?

我是研究僧i 提交于 2020-01-25 00:06:22
问题 I'm trying to return attributes of columns from my DataContext. How can I pull out the ColumnAttribute meta data? public class MyDataContext : DataContext { public Table<User> User; public MyDataContext(string connection) : base(connection) { } } [Table(Name = "User")] public class User { [Column(IsPrimaryKey = true)] public long ID; [Column] public string FirstName; [Column(CanBeNull=false)] public string LastName; int VersionNumber = 1000; } How do I access the User object or Table<User>

Getting property value based on its column attribute value

不羁的心 提交于 2020-01-04 05:11:27
问题 List<MyModel1> myModel1 = new List<MyModel1>(); MyUserModel myUserModel = new MyUserModel(); List<MyModel2> myModel2 = new List<MyModel1>(); myModel1 = m_Service1.GetMyModelFields(); myUserModel = m_Service2.GetMyUserDetails(); myModel2 = (from myModel1Field in myModel1 select new MyModel2 { FieldCaption = myModel1Field.FieldAlias, FieldValue = "" }).ToList<MyModel2>(); myModel1Field.FieldAlias text will be same as value of one of the Column attribute of one of the property in myUserModel. So

Mapping a URI to String-field in LINQ-to-SQL

被刻印的时光 ゝ 提交于 2019-12-08 02:37:44
问题 I'm trying to store a URI as a string in a database, using LINQ. [Column(Name = "Url", DbType = "nvarchar(255)")] public Uri Url { get { return new Uri(_url); } set { _url = value.AbsoluteUri; } } private string _url; This maps nicely to my database design, however, when trying to fetch data using this code: int id = 3; _serie = new DataContext(connString).GetTable<Serie>(); var serie = _serie.FirstOrDefault(s => s.Id == id); At the last line, I get an exception System.InvalidCastException:

Object Mapping from stored procedure using the columnname attribute in EntityFramework CodeFirst

不想你离开。 提交于 2019-12-06 11:39:11
问题 I have an existing db that I am using entityframework 6 Code-First on to work with. A requirement though is that all work with the db has to be via stored procedures. So I started out using the mapping that is new in 6.0: modelBuilder.Entity<Post>().MapToStoredProcedures(); The issue is that this only supports mapping Insert, Update, and Delete sp's not the select sp's, I need to be able to us a sp to select. (I do not have access to edit any of the existing sp's) My poco's have attributes on